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,
Andreas

Comments

  1. Hi...

    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.

    ReplyDelete
  2. 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?

    ReplyDelete
  3. 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.

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

    CrmEncodeDecode is not defined

    ReplyDelete
    Replies
    1. Hi m2012,

      Are you running this outside CRM?
      You might want to check this out:
      http://mscrmkb.blogspot.com.au/2011/12/crm-2011-javascript-giving-error.html

      Delete
  5. Andreas

    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

    Andrew

    ReplyDelete
    Replies
    1. Hi,

      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

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

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

      Delete

Post a Comment

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline

Sitecore custom publish agent from specific node and at a specific time