crm 2011 -- processing SOAP response
-
Wednesday, 29 February, 2012 9:57 PM
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; } },
All Replies
-
Wednesday, 29 February, 2012 10:29 PMAnswerer
Hi,
You need to use Xpath queries on the XmlDocument.
Scott Durow
Read my blog: www.develop1.net/public
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Proposed As Answer by Travis-Sharp Wednesday, 29 February, 2012 11:28 PM
- Marked As Answer by FutureSteel Thursday, 1 March, 2012 2:23 PM
- Unmarked As Answer by FutureSteel Thursday, 1 March, 2012 8:04 PM
-
Thursday, 1 March, 2012 2:23 PMThank you sir...
-
Thursday, 1 March, 2012 8:02 PM
Scott,
I've tried parsing it, and maybe it's just me, but does the XML response includes the "\" on every line. If i save the response as an XML file it errors out until i remove the "\". Do you have any suggestions on how i can make it work?
-
Thursday, 1 March, 2012 8:29 PM
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:56 PM
Thanks Aleksey i'll give it a shot.
But how would you pull the address values using SOAP?