locked
How to create a record using InitializeFromRequest RRS feed

  • Question

  • Hello, I am trying to create a record in entity quote basing on another quote.
    For that I am using the InitializeFromRequest function to the registration request:

    InitializeFromRequest: function () {
                   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:InitializeFromRequest\" 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>EntityMoniker</c:key>";
                   requestMain += "            <c:value i:type=\"a:EntityReference\">";
                   requestMain += "              <a:Id>"+id+"</a:Id>";
                   requestMain += "              <a:LogicalName>quote</a:LogicalName>";
                   requestMain += "              <a:Name i:nil=\"true\" />";
                   requestMain += "            </c:value>";
                   requestMain += "          </a:KeyValuePairOfstringanyType>";
                   requestMain += "          <a:KeyValuePairOfstringanyType>";
                   requestMain += "            <c:key>TargetEntityName</c:key>";
                   requestMain += "            <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">quote</c:value>";
                   requestMain += "          </a:KeyValuePairOfstringanyType>";
                   requestMain += "          <a:KeyValuePairOfstringanyType>";
                   requestMain += "            <c:key>TargetFieldType</c:key>";
                   requestMain += "            <c:value i:type=\"b:TargetFieldType\">All</c:value>";
                   requestMain += "          </a:KeyValuePairOfstringanyType>";
                   requestMain += "        </a:Parameters>";
                   requestMain += "        <a:RequestId i:nil=\"true\" />";
                   requestMain += "        <a:RequestName>InitializeFrom</a:RequestName>";
                   requestMain += "      </request>";
                   requestMain += "    </Execute>";
                   requestMain += "  </s:Body>";
                   requestMain += "</s:Envelope>";
                   var req = new XMLHttpRequest();
                   req.open("POST", SDK.SAMPLES._getServerUrl(), true)
                   // Responses will return XML. It isn't possible to return JSON.
                   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");
                   var successCallback = function(){
                      var XMLResp=req.response;
                      SDK.SAMPLES.parseResponse(XMLResp,'customerid');
                      debugger;
    //SDK.REST.createRecord(objectValues, "quote", function () { alert("ad"); }, function (error) { alert(error.message); });
                   };
                   var errorCallback = function (err){
                            console.log(err);
                          };
                   req.onreadystatechange = function () { SDK.SAMPLES.InitializeFromResponse(req, successCallback, errorCallback); };
                   req.send(requestMain);
               },

    The problem is that this query returns an XML but does not bring the columns of the record. I searched and I read that I have to map some fields with 1:N relationship to bring me al fields of record in the XML, but I dont know how.
    This is the XML that is returned in InitializeFromResponse:

    "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
    <s:Body><ExecuteResponse xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\">
    <ExecuteResult i:type=\"b:InitializeFromResponse\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">
    <a:ResponseName>InitializeFrom
    </a:ResponseName><a:Results xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">
    <a:KeyValuePairOfstringanyType><c:key>Entity</c:key><c:value i:type=\"a:Entity\">
    <a:Attributes><a:KeyValuePairOfstringanyType><c:key>iniker_ofertadestinocopia</c:key><c:value i:type=\"a:EntityReference\"><a:Id>afcb53d7-1c27-e611-80d0-00155d00da08</a:Id><a:LogicalName>quote</a:LogicalName><a:Name>a</a:Name></c:value></a:KeyValuePairOfstringanyType></a:Attributes><a:EntityState i:nil=\"true\"/><a:FormattedValues/><a:Id>00000000-0000-0000-0000-000000000000</a:Id><a:LogicalName>quote</a:LogicalName><a:RelatedEntities/></c:value></a:KeyValuePairOfstringanyType></a:Results></ExecuteResult></ExecuteResponse></s:Body></s:Envelope>"

    I need fields not returned in XML, for example customerid.

    thansk & regards.

    Ion Bengoetxea.

    • Edited by ioniben Tuesday, June 14, 2016 11:12 AM
    Tuesday, June 14, 2016 11:04 AM