none
crm 2011 -- processing SOAP response

    Question

  • My SOAP request works great.  Below is my SOAP response.  How do i pull the address values out of it?

    <s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
      <s:Body>
        <RetrieveResponse xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\">
          <RetrieveResult xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">
            <a:Attributes xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">
              <a:KeyValuePairOfstringanyType>
                <b:key>new_address1</b:key>
                <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">123 Fake Street</b:value>
              </a:KeyValuePairOfstringanyType>
              <a:KeyValuePairOfstringanyType>
                <b:key>new_address2</b:key>
                <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">123</b:value>
              </a:KeyValuePairOfstringanyType>
              <a:KeyValuePairOfstringanyType>
                <b:key>new_city</b:key>
                <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">Calgary</b:value>
              </a:KeyValuePairOfstringanyType>
              <a:KeyValuePairOfstringanyType>
                <b:key>new_country</b:key>
                <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">Canada</b:value>
              </a:KeyValuePairOfstringanyType>
              <a:KeyValuePairOfstringanyType>
                <b:key>new_postalcode</b:key>
                <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">T2V1v2</b:value>
              </a:KeyValuePairOfstringanyType>
              <a:KeyValuePairOfstringanyType>
                <b:key>new_stateprovince</b:key>
                <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">AB</b:value>
              </a:KeyValuePairOfstringanyType>
              <a:KeyValuePairOfstringanyType>
                <b:key>new_quickquoteid</b:key>
                <b:value i:type=\"c:guid\" xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/\">c2ca7072-8b56-e111-b13c-782bcb2d6a7d</b:value>
              </a:KeyValuePairOfstringanyType>
            </a:Attributes>
            <a:EntityState i:nil=\"true\"/>
            <a:FormattedValues xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\"/>
            <a:Id>c2ca7072-8b56-e111-b13c-782bcb2d6a7d</a:Id>
            <a:LogicalName>new_quickquote</a:LogicalName>
            <a:RelatedEntities xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\"/>
          </RetrieveResult>
        </RetrieveResponse>
      </s:Body>
    </s:Envelope>

    Below is sad attempt to try and get the address out of it. I can't get past "a:KeyValuePairOfstringanyType" because it can't find it.

    _getSuccess: function (responseXml, route) {
            switch (route) {
                case 'shipping':
                    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async = "false";
                    xmlDoc.loadXML(responseXml.xml);
                    x = xmlDoc.getElementsByTagName("a:KeyValuePairOfstringanyType");
                    for (i = 0; i < x.length; i++) {
                        var y = xmlDoc.getElementsByTagName("a:EntityReference");
                        for (j = 0; j < y.length; j++) {
                            if (y[j].getElementsByTagName("a:LogicalName")[0].text == "opportunity") {
                                var oppId = y[j].getElementsByTagName("a:Id")[0].text;
                                var serverUrl = Xrm.Page.context.getServerUrl();
    
                                // Cater for URL differences between on premise and online
                                if (serverUrl.match(/\/$/)) {
                                    serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                                }
                            }
                        }
                    }
                    break;
                case 'setstate':
                    window.location.reload(true);
                    break;
                default:
                    break;
            }
        },





    Wednesday, 29 February, 2012 9:57 PM

Answers

  • Hi,

    As far as I understand \" is just a way to visualize ", so in reality there is no \ character in your response.

    Take a look at this project, it might be interesting for you: http://xrmservicetoolkit.codeplex.com/

    And on a side note AcitveXObject will work for IE only.

    • Marked as answer by FutureSteel Wednesday, 28 March, 2012 3:15 PM
    Thursday, 1 March, 2012 8:29 PM

All replies