0
我有這個javascript解析代碼,當在案例上按下「解析」按鈕時它會被調用。CRM 2011 - 在解決之前保存事件更改
function CloseIncidentRequest(incidentId) {
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:CloseIncidentRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>IncidentResolution</c:key>";
requestMain += " <c:value i:type=\"a:Entity\">";
requestMain += " <a:Attributes>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>incidentid</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>" + incidentId + "</a:Id>";
requestMain += " <a:LogicalName>incident</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>subject</c:key>";
requestMain += " <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">Parent Case has been resolved</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Attributes>";
requestMain += " <a:EntityState i:nil=\"true\" />";
requestMain += " <a:FormattedValues />";
requestMain += " <a:Id>00000000-0000-0000-0000-000000000000</a:Id>";
requestMain += " <a:LogicalName>incidentresolution</a:LogicalName>";
requestMain += " <a:RelatedEntities />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>Status</c:key>";
requestMain += " <c:value i:type=\"a:OptionSetValue\">";
requestMain += " <a:Value>140310001</a:Value>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>CloseIncident</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
var serverUrl = Xrm.Page.context.getServerUrl();
var oDataEndpointUrl = serverUrl + "/XRMServices/2011/Organization.svc/web";
req.open("POST", oDataEndpointUrl, false)
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.send(requestMain);
if (req.responseXML.getElementsByTagName("faultstring").length == 0)
window.location.reload(true);
else
alert(req.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue);
}
我需要保存非保存的更改做的情況下(如果有的話)解決它之前。 我試過CloseIncidentRequest函數的調用,但它不工作之前添加此
Xrm.Page.data.entity.save("save");
,更改將丟失的情況下得到解決。我也嘗試過「saveandclose」,但它也沒有做到這一點。我也嘗試在保存之後和解決之前刷新頁面,但它也沒有工作。
我也有一個插件,它觸發了案件的「OnClose」事件,但我不知道一種方法來檢索我試圖解決的案例所做的未保存更改。
我可以去任何一種方式,從JavaScript或從插件。我只需要保存更改,不會丟失。
任何想法可以幫助我嗎? 謝謝!
是的。不工作! – Nicole
我想你需要重寫'Case Close'事件。 – Scorpion
通過這個博客,我相信你會得到一個想法:http://social.technet.microsoft.com/wiki/contents/articles/4122.dynamics-crm-2011-perform-jscript-validations-on-entity -form-before-execution-of-special-events.aspx – Scorpion