I was working on a project for an associate this morning and needed to generate a SOAP message that would query CRM using the web service API from JavaScript.  After Googling around a bit, I ran into one of the most useful tools I've seen in a while.

My friend and fellow CRM MVP Michael Höhne has a little utility that will generate a complete set of JavaScript that will not only query the CRM database, but he also includes code to execute the SOAP message and return it's result set as an XML document.

Further Googling found an article on A List Apart that enabled me to extract a value for a node within the XML result set.  I modified it slightly to add some error correction.  Place the following code at the bottom of the JavaScript generated by the default sample in Michael's utility:

 

var myValue = getNodeValue(resultXml, 'emailaddress1');

alert(myValue);

function getNodeValue(tree, el)
{
   var retVal = null;
   var e = null;
   e = tree.getElementsByTagName(el);

   if (e != null && e[0] != null)
   {
       retVal = e[0].firstChild.nodeValue;
   }

    return retVal;
}

This will parse the XML result set and display the main email address for the Account.

Great work again Michael.