C# CRM 2011-在解决之前保存事件更改

C# CRM 2011-在解决之前保存事件更改,c#,javascript,dynamics-crm-2011,dynamics-crm,C#,Javascript,Dynamics Crm 2011,Dynamics Crm,我有一个javascript解析代码,当按下案例上的“resolve”按钮时会调用它 function CloseIncidentRequest(incidentId) { var requestMain = "" requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"; requestMain += " <s:Body>";

我有一个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);
}
在调用CloseIncidentRequest函数但其不起作用之前,更改将丢失,案件将得到解决。我还尝试了“saveandclose”,但也没有成功。我还尝试在保存后和解析前刷新页面,但也不起作用

我也有一个插件,可以触发案例的“OnClose”事件,但我不知道如何检索对我试图解决的案例所做的未保存更改

我可以选择任何一种方式,从javascript或插件。我只需要保存更改,它们不会丢失

有什么想法可以帮助我吗?
谢谢

您是否已尝试按以下方式保存该案例

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();
                }                   
        }
    }
}

作为参考,请浏览博客。

我认为您需要覆盖
案例关闭事件。
浏览此博客,我相信您会有一个想法:我似乎不明白这对我有什么帮助。。由于我不需要验证,如果用户试图在不保存更改的情况下解决问题,我需要保存未保存的数据。。
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();
                }                   
        }
    }
}