CRM 2011 Javascript Fetch XML synchronous or asynchronous call

Using helper function to execute FetchXML request is great.

The code below is retrieved from this blog, and all I had to do is to add extra logic when parsing the XML result because I want to grab the attributes from the related entity as well.

Modified FetchUtil.js:

To use it you just need to do it like this (synchronous)

If it's asynchronous the last bit will be:

The parsed result object can be queried like this:

Hope this helps,



Thanks a lot for share your knowledge with us. Okay, while this method does enable you to execute a FetchXML request in JavaScript against the 2011 SOAP endpoint, it doesn't return XML in the same format as the 4.0 web service did.

Keep sharing.


hey it works on me but when i try to save the form it gives an error message:

“An Error has occurred. Try this action again. If the problem continues, check the Microosft Dynamics CRM Community for solutions or contact your Microsoft Dynamics administrator. Finally, you can contact Microsoft Support.”

can u help me?


Hi Ahmet, what happens after you click ok to that message?
I believe that error message is not related to this as it doesn't look like a JS error.


I got error at request += CrmEncodeDecode.CrmXmlEncode(sFetchXml); this line

CrmEncodeDecode is not defined


Hi m2012,

Are you running this outside CRM?
You might want to check this out:



Where did you get the information for the a:AliasedValue from - the code is failing for me as all that seems to be there is the name which is in attr.childNodes[k].childNodes[1].childNodes[2].childNodes[0].text; and the other childnodes are not there (e.g. attr.childNodes[k].childNodes[1].childNodes[2].childNodes[1].text;) making the code fail?

I am reading the parent account name from the contact




Sorry I can't remember what I used AliasedValue for - but I needed it that's why I put it there I believe. If you don't need those attributes feel free to remove it to make it work on your end :D


Thanks for sharing. I'm getting "Access is deined" error. Can some one guide me how to avoid this.


Are you a system administrator? it might be entity permission issue.


Post a Comment