我是Dynamics CRM的新手并尝试执行任务。 我已在“发票”表单上创建了一个自定义按钮,作为" Mark Paid"并隐藏了之前已存在的按钮" Invoice Paid"。我想为此做一些额外的功能"马克付费"按钮,除了这个问题,我已经很好地完成了它们: - 点击" Mark Paid"有四个功能,我打电话给他。按键 其中一个函数是MarkPaid();所有这些功能都是javascript函数。这是我的MarkPaid()函数代码:
function MarkPaid() {
if (Xrm.Page.data.entity.getIsDirty()) {
alert("Save the Invoice and try again");
return;
}
var req = ""
req += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
req += "<s:Body>";
req += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
req += "<request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
req += "<a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
req += "<a:KeyValuePairOfstringanyType>";
req += "<b:key>EntityMoniker</b:key>";
req += "<b:value i:type=\"a:EntityReference\">";
req += "<a:Id>" + Xrm.Page.data.entity.getId() + "</a:Id>";
req += "<a:LogicalName>invoice</a:LogicalName>";
req += "<a:Name i:nil=\"true\" />";
req += "</b:value>";
req += "</a:KeyValuePairOfstringanyType>";
req += "<a:KeyValuePairOfstringanyType>";
req += "<b:key>State</b:key>";
req += "<b:value i:type=\"a:OptionSetValue\">";
req += "<a:Value>2</a:Value>";
req += "</b:value>";
req += "</a:KeyValuePairOfstringanyType>";
req += "<a:KeyValuePairOfstringanyType>";
req += "<b:key>Status</b:key>";
req += "<b:value i:type=\"a:OptionSetValue\">";
req += "<a:Value>100001</a:Value>";
req += "</b:value>";
req += "</a:KeyValuePairOfstringanyType>";
req += "</a:Parameters>";
req += "<a:RequestId i:nil=\"true\" />";
req += "<a:RequestName>SetState</a:RequestName>";
req += "</request>";
req += "</Execute>";
req += "</s:Body>";
req += "</s:Envelope>";
var serverUrl = Xrm.Page.context.getClientUrl() +
"/XRMServices/2011/Organization.svc/web";
var req = new XMLHttpRequest();
req.open("POST", serverUrl, true)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.onreadystatechange = function () {
assignResponse(req);
};
req.send(req);}
function assignResponse(req) {
if (req.readyState == 4) {
if (req.status == 200) {
window.location.reload(true);
}
else {
alert("Error Marking Invoive Paid: " +req.responseXML);
}
}}
当此功能执行时,发票应标记为&#34;支付&#34;和#34;完成&#34;。 代码正在执行,但我收到警告框,显示错误消息&#34;错误使发票付款&#34;所以我猜我的代码有问题。
感谢任何帮助..谢谢