我有这个javascript解析代码,当在案例上按下“Resolve”按钮时,它会被调用。
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);
}
我需要将未保存的更改保存到案例中(如果有的话)在解决之前。 我试着添加这个
Xrm.Page.data.entity.save("save");
在调用CloseIncidentRequest函数之前,但它不起作用,更改将丢失并且案例已解决。我也试过“saveandclose”,但它也没有做到这一点。我也尝试在保存之后和解决之前刷新页面,但它也没有用。
我还有一个插件可以触发案件的“OnClose”事件,但我不知道如何检索我正在尝试解决的案例中未保存的更改。
我可以从javascript或插件中找到任何一种方式。我只需要保存更改它们不会丢失。
任何可能对我有帮助的想法? 谢谢!
答案 0 :(得分:0)
您是否尝试将案例保存如下。
Xrm.Page.data.entity.save();
<强>更新强>
将以下javascript放在表单的保存事件中。我没有测试过,你可能需要调整它。
function FrmOnSave(prmContext) {
// Local variable to store value indicating how the save event was initiated by the user.
var wod_SaveMode, wod_SaveEventVal;
// Change the Save Event Value as per required Save Event
wod_SaveEventVal = 5;
if (prmContext != null && prmContext.getEventArgs() != null) {
wod_SaveMode = prmContext.getEventArgs().getSaveMode();
if (wod_SaveMode == wod_SaveEventVal) {
// Write your validation code here
var ismodified = Xrm.Page.data.entity.getIsDirty();
if(ismodified == true)
{
alert("please save the changes first");
prmContext.getEventArgs().preventDefault();
}
}
}
}
供参考,请浏览this博客。