crm 2011 -- processing SOAP response
-
woensdag 29 februari 2012 21:57
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; } },
Alle reacties
-
woensdag 29 februari 2012 22:29Beantwoorder
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"- Als antwoord voorgesteld door Travis-Sharp woensdag 29 februari 2012 23:28
- Als antwoord gemarkeerd door FutureSteel donderdag 1 maart 2012 14:23
- Markering als antwoord ongedaan gemaakt door FutureSteel donderdag 1 maart 2012 20:04
-
donderdag 1 maart 2012 14:23Thank you sir...
-
donderdag 1 maart 2012 20:02
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?
-
donderdag 1 maart 2012 20:29
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.
- Als antwoord gemarkeerd door FutureSteel woensdag 28 maart 2012 15:15
-
donderdag 1 maart 2012 20:56
Thanks Aleksey i'll give it a shot.
But how would you pull the address values using SOAP?