Retrieve records using Fetch XML & Java Script in CRM 2011/13

Task: Retrieve Arun Potti Business Phone on onload of Contact record in Contact Entity using FetchXML & Javascript

Solution:

Step 1: Goto http://xrmsvctoolkit.codeplex.com/, and download the Zip folder. Unzip XrmServiceToolkit the folder.

Step 2: Open the XrmServiceToolkit folder, you can find the below Javascript files.

FetchXML - Pic 1

Goto Microsoft Dynamics CRM –> Settings –> Customization –> Webresources.

Create jquery, json2 and XrmServiceToolkit javascript webresources. While creating web resources browse for the respective files and provide the path of XRMServiceToolkit.

Step 3: Add all 3 files to the contact entity,

FetchXML - Pic 2

Step 4: Goto Microsoft Dynamics CRM –> Sales –> Contacts, click on Advance find button. Create new criteria as shown below by clicking on New button,

FetchXML - Pic 3

Step 5: Click on Download Fetch XML button, to get FetchXML code. You can see the below XML,

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="contact">
    <attribute name="fullname" />
    <attribute name="telephone1" />
    <attribute name="contactid" />
    <order attribute="fullname" descending="false" />
    <filter type="and">
     <condition attribute="fullname" operator="eq" value="Arun Potti" />
    </filter>
  </entity>
</fetch>

Step 6: We have to change the format of the above FetchXML to use in Javascript.

Use FetchXML Formatter Tool to modify the format.

To Know more about FetchXML Formatter Tool click Here

After modifying its looks like the below,

"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"  <entity name='contact'>"+
"    <attribute name='fullname' />"+
"    <attribute name='telephone1' />"+
"    <attribute name='contactid' />"+
"    <order attribute='fullname' descending='false' />"+
"    <filter type='and'>"+
"      <condition attribute='fullname' operator='eq' value='Arun Potti' />"+
"    </filter>"+
"  </entity>"+
"</fetch>"

Step 7: Now create new_contactJscript Webresource and paste the below code,

function contactOnload() {
 var contactFetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
 "  <entity name='contact'>"+
 "    <attribute name='fullname' />"+
 "    <attribute name='telephone1' />"+
 "    <attribute name='contactid' />"+
 "    <order attribute='fullname' descending='false' />"+
 "    <filter type='and'>"+
 "      <condition attribute='fullname' operator='eq' value='Arun Potti' />"+
 "    </filter>"+
 "  </entity>"+
 "</fetch>";
var contactRecords = XrmServiceToolkit.Soap.Fetch(contactFetchXML);
if (contactRecords.length > 0) {
 if (contactRecords[0].attributes.telephone1 != undefined)
   alert(contactRecords[0].attributes.telephone1.value);
  }
}

Step 8: Add the new_contactJscript Webresource to Form Libraries on contact Form, and add the contactOnload function to Onload Event,

FetchXML - Pic 5

Step 9: Click on Ok. Save & Publish the contact Entity.

Step 10: Open the existing contact record to see the below pop up,

FetchXML - Pic 6

 


Discover more from Arun Potti's Power Platform blog

Subscribe to get the latest posts to your email.

45 thoughts on “Retrieve records using Fetch XML & Java Script in CRM 2011/13

  1. Hey very nice website!! Guy .. Excellent .. Supereb .. I will bookmark your web site
    and take the feeds also? I am glad to sek out numerous
    helpful information right here within the submit, we
    wannt develokp extra techniques on this regard, thank you for sharing.
    . . . . .

    • Hi Palano,
      Thank you very much.
      Open arunpotti.wordpress.com and
      You can see “Follow” on the Bottom Right of the Page. Give your Email Id to Subscribe.

  2. Have yoou ever considered publishing an e-book or guest authoring on othe websites?
    I have a blog based on the same topics you discuss and would really like to have you share some
    stories/information. I now my audience would appreciate your work.
    If you are even remotely interested, feel free to shoo
    me ann email.

  3. It’s appropriate time to make somne plans for the
    future and it is time to be happy. I have read this post and if I could I wish to
    suggest you some interestin things or advice.
    Maybe you could write next articles referring to thhis article.
    I want to read even more things about it!

  4. Wow, fantastic blog layout! Howw long have you beern blogging for?
    you make blogging look easy. The ovrrall look of your site is magnificent, let alone the content!

  5. Hmm is anytone else having problems with the images on this blog loading?
    I’m trying to figure out if its a problem on my end or if it’s
    the blog. Any feedback would be greatly appreciated.

  6. Hey, I think your website might be having browser compatibility issues.

    When I look at your website in Firefox, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I jusat wanted to give yoou a quick heads
    up! Other thenn that, terrific blog!

  7. Thanks for a marvelous posting! I actually enjoyed reading it,
    you are a great author. I will ensure that I
    bookmark your blog and will eventually come back in the
    future. I want to encourage that you continue your great work, have
    a nice weekend!

  8. Wonderful beat ! I wish to apprenticee while
    you amend your website, how could i subscribe for a
    blog site? The account helped me a acceptable deal.

    I hadd been a little bit acquainted of this your broadcast provided bright clear concept

    • Hi Candra,
      Thank you very much.
      Browse arunpotti.wordpress.com and
      You can see “Follow” on the Bottom Right of the Page. Give your Email Id to Subscribe.

  9. Hmm it appears like your website ate my first comment (it was extremely long) so I guess I’ll just sum it up
    what I had written and say, I’m thoroughly enjoying your blog.

    I ass well am an aspiring bloog blogger but I’m still neww to everything.
    Do you have any tips and hints for newbie blog writers? I’d really appreciate it.

    • Thank you Carina for reading my blog 🙂

      Only one Tip which i follow while writing blog, should be very clear with articles, so everyone can understand easily.

  10. I have been exploring for a little for any high-quality articles or weblog posts on this sort of area
    . Exploring in Yahoo I finally stumbled upon this wweb site.
    Studying this information So i am happy to express that I havbe an incredibly just right uncanny
    feeling I found out just what I needed. I such a lot undoubtedly will
    make certain to don?t put out of your mind this site and
    provides it a look on a relentless basis.

  11. Thanks so much. I got lazy though and implemented without the xmlformatter stage – it seems to be working fine!??? Best wishes.

  12. Hello! Someone in my Facebook group shared this website with
    us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will
    be tweeting this to my followers! Great blog and fantastic design and style.

  13. “Great Blogpost! Hello Admin! Thanks for this article, very good information, I will be_ forwarding this to some friends, if you’re ok with that. Greetings from Germany!”

  14. It’s in reality a nice and helpful piece of info.

    I’m satisfied that you shared this helpful information with us.
    Please stay us informed like this. Thanks for sharing.

  15. I was suggested this blog by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my problem. You are wonderful! Thanks!

Leave a Reply to EvaCancel reply