web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Reading from ResponseXML SOAP to Xrm Page

(0) ShareShare
ReportReport
Posted on by 2,585

Hello There,

So today i started to work on SOAP concepts. i was working on this example where based on GUID of contact we retrieve all its details.

function readme(){
var xml = "" + 
"<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../\"><s:Body><Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\"><request i:type=\"a:RetrieveRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\"><a:Parameters xmlns:b=\"schemas.datacontract.org/.../b:key><b:value i:type=\"a:EntityReference\"><a:Id>604e43ed-7d63-e411-88fc-9cb6548d72f4</a:Id><a:LogicalName>contact</a:LogicalName><a:Name i:nil=\"true\"/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>ColumnSet</b:key><b:value i:type=\"a:ColumnSet\"><a:AllColumns>true</a:AllColumns><a:Columns xmlns:c=\"schemas.microsoft.com/.../a:Parameters><a:RequestId i:nil=\"true\"/><a:RequestName>Retrieve</a:RequestName></request></Execute></s:Body></s:Envelope>" + 
"";

//var xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
//var xmlHttpRequest  = new ActiveXObject("Msxml2.XMLHTTP");

if (window.XMLHttpRequest) {
      xmlHttpRequest=new XMLHttpRequest();                   // For all modern 
  } else if (window.ActiveXObject) {
     xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");  // For (older) IE
  }


xmlHttpRequest.open("POST", Xrm.Page.context.getClientUrl() +"/XRMServices/2011/Organization.svc/web", false);
xmlHttpRequest.setRequestHeader("SOAPAction","schemas.microsoft.com/.../Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseText;
alert(resultXml); //This printed out the response well.

var resultXml1 = xmlHttpRequest.responseXML;

alert("The real  value" +resultXml1);


}

for the above code i have Updated SOAPlogger. :)


I have looked at responseXML and found it has all the feilds like lastname,address, and other stuff.

what i need to know is , how do i get the data from the responseXML and show it on Xrm form (Ex: say Alert box of lastname)

Any ideas? :)

Guide me onto those resources please,

Thank you

*This post is locked for comments

I have the same question (0)
  • Deepesh161 Profile Picture
    6,317 on at

    Hi,

    You will need to parse resultxml. Add a debugger and dynamically read the fields from inside the resultxml.

    Once you know the result values(How to parse them), you can just use the same in script.

    Here is a 2011 sample: https://community.dynamics.com/crm/b/crmsoftwareblog/archive/2011/05/19/parsing-and-consuming-the-crm-2011-soap-service-inside-javascript.aspx

    Regards,

    Deepesh

    dynamicsofdynamicscrm.wordpress.com

  • Royal King Profile Picture
    27,686 on at

    You have to parse the xml to get the required value. Rather than repeating this kind of code  all over your javascript , you could use library like Xrmservicetoolkit to simplify all soap and ODATA calls in Javascript.

    xrmservicetoolkit.codeplex.com

    Here is the script that will retrieve lastname from the response xml.

    resultXml .selectSingleNode("//a:lastname").nodeTypedValue;

  • omgcrm Profile Picture
    2,585 on at

    Hello Deepesh Somani.

    resultXml1 or resultXml?

    and please provide me with any working example.

    it would be of great help.

  • Deepesh161 Profile Picture
    6,317 on at

    I edited the original response, it has a sample.check that out.

    Regards,

    Deepesh

    dynamicsofdynamicscrm.wordpress.com

  • omgcrm Profile Picture
    2,585 on at

    hello  Chitrarasan Duraisamy

    resultXml .selectSingleNode("//a:lastname").nodeTypedValue;

    object does not support property or method selectSingleNode

  • omgcrm Profile Picture
    2,585 on at

    hi Deepesh Somani ,

    Thanks for the link :) i will go through it.

    could you tell me the way to get the lastname from that responseXML and store it onto field in Crm(Xrm page feilds)

  • Royal King Profile Picture
    27,686 on at

    It looks like you are reading reponsetext rather response Xml . Try the below code to select lastname

    var resultXml =xmlHttpRequest.responseXML;

    var lastname = resultXml .selectSingleNode("//a:lastname").nodeTypedValue;

  • Saroj Das Profile Picture
    3,355 on at

    Hi Sreekanth, please try this below code to read responseXml.

    resultXml.selectNodes("//BusinessEntity/q1:" + pAttributeName);

    or

    resultXml.selectSingleNode("//q1:" + columns).attributes[0].text;

    or

    var v = xmlObj.childNodes(0).getAttribute("id");

    or you can check below link

    msdn.microsoft.com/.../gg594428.aspx

    Thanks,

    Saroj

  • omgcrm Profile Picture
    2,585 on at

    Saroj Das

    Guys i am stuck at this part. not able to understand. Give Examples for my scenario please

    var resultXml = xmlHttpRequest.responseText;

    alert(resultXml);

    var resultXml1 = xmlHttpRequest.responseXML;

    var do1 = resultXml1.selectSingleNode("//a:lastname").attributes[0].text;

    alert("The Do stuff is " +do1);

    here i get error for selectSingleNode - object does not support property.

  • Suggested answer
    Saroj Das Profile Picture
    3,355 on at

    Hi Sreekanth, the problem is because of xpath. are you using IE 10 ? if so then IE 10 and other browsers doesn't support xpath. please veryfy below link.

    www.w3schools.com/.../xpath_examples.asp

    Thanks,

    Saroj

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans