Tuesday, June 11, 2013

Format of Jscript SOAP Responses in Microsoft Dynamics CRM 2011 Organization Service has Changed in UR 12!

You used to be able to pass in your response.responseXML.xml into a function like the one below to parse out a response and pull individual attributes.

function parseResponse(responseXML, attributename) {

    debugger;
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(responseXML);
    x=xmlDoc.getElementsByTagName("a:KeyValuePairOfstringanyType");
    for (i=0;i<x.length;i++)
   {
      if (x[i].childNodes[0].text == attributename)
      {
         //we decode the base 64 contents and alert the HTML of the Iframe
          alert(x[i].childNodes[1].text);
      }
      
   } 
}

PROBLEM:  With UR 12 and above you can still use this type of function but the responseXML property no longer exists on the response object.

SOLUTION: now instead of passing in your myresponse.responseXML.xml property of your response, now the property of your reponse is just in a  new response property, so the new syntax would just be myresponse.response

I hope this helps!!

-

7 comments:

  1. Hey Jamie,

    how is the code above changing if working with myresponse.response?

    Thanks!

    ReplyDelete
    Replies
    1. Or code like this:

      var bodyNode = req.responseXML.firstChild.firstChild;
      for (var i = 0; i < bodyNode.childNodes.length; i++) {
      var node = bodyNode.childNodes[i];
      //NOTE: This comparison does not handle the case where the XML namespace changes
      alert("hier");
      if ("CreateResponse" == node.nodeName) {
      var newQuoteId = node.firstChild.text;
      alert("ID:" + newQuoteId);
      return newQuoteId;
      }
      else {
      alert("Der Vertrag konnte nicht kopiert werden.");
      break;
      }

      Delete
    2. The code isn't actually changing above, you are changing what you are passing into it. :)

      Delete
  2. This comment has been removed by the author.

    ReplyDelete