简体   繁体   中英

Close Incident in CRM 2011 with Silverlight

I have an big issue to close an incident with the Dynamics CRM 2011 Organization Service. There is no CloseIncidentRequest class avaiable and also with fetch xml I've no chance:

        public void CloseCase(Guid pCaseId)
    {
        FetchExpression fetch = new FetchExpression();
        String 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>{0}</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>{1}</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>5</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>";

        fetch.Query = String.Format(requestMain, pCaseId.ToString(), pCaseId.ToString());

        _orgService.BeginRetrieveMultiple(fetch, CloseCaseResult, null);

Any idea to solve this problem?

Best Regards

Recheck following article about calling of IOrganizationService in silverlight - http://mileyja.blogspot.com/2011/06/retrieve-entity-in-microsoft-dynamics.html

First part of code (creation of request) should be replaced with following code:

    Entity incidentresolution = new Entity()
    {
        LogicalName = "incidentresolution"
    };
    incidentresolution["subject"] = "Incident was closed";
    incidentresolution["incidentid"] = new EntityReference()
    {
        Id = Guid.Empty,
        LogicalName = "incident"
    };

    OrganizationRequest request = new OrganizationRequest()
    {
        RequestName = "CloseIncident"
    };

    request["incidentresolution"] = incidentresolution;
    request["status"] = new OptionSetValue()
    {
        Value = -1
    };

Of course you should replace Guid.Empty with id of incident you want to close.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM