JavaScript Fetch XML–Supporting IE10 and Other Browsers

Last year we looked at building FetchXML support with JavaScript and these two blog posts were quite popular.  Surprisingly a few people at CRMUG thanked me for these specific blog posts.  At CRMUG we got into a great discussion about the indirect benefits of using FetchXML versus OData and that led to someone mentioning the lack of support with my JavaScript code on non-IE browsers.  After coming back home to Greenville, I realized the code also fails to work in IE10.  Coincidentally we had some users who switched to Windows 8 mention our internal Gantt chart had to be run in compatibility mode to support IE10.

image

So today we’re going to look into updating the JavaScript FetchXML code to support Chrome, Firefox, Safari and especially Internet Explorer 10.

 

Why not use OData?

Before we get started though, I want mention that OData is great.  The only reason I took the time to build out the initial fetch support was due to the complex querying that Fetch supports.  Additionally, aggregates are only available with FetchXML.  I still use OData but I often prefer FetchXML due to the flexibility and ease.  I also prefer to use FetchXML with my C# code which offers several benefits including consistency when developing.

Secondly, I want to mention that when building your FetchXML you want to use a tool.  An easy way is to use the Advanced Find and then click the Download Fetch XML button.

image

There are other tools available, like Stunnware Tools (which has moved to http://www.donaubauer.com/en/#!CrmInterface).  Find what fits you.

 

Getting Started

The first thing I had to do was switch to using the DOMParser.  Granted I’ve done a lot of development on non-IE browsers, but when it comes to XML, Internet Explorer has always done it very well (Gone are the days of XPath my friends).

image

Note: IE9 supports both parts of this IF clause but will use the DOMParser in this conditional statement.

 

This next bit of code highlights the slight nuances with the different parsers.  The ActiveX approach would call the attribute by “baseName” and the value “text”; whereas, the DOMParser uses “localName” and “textContent” respectively.

image

 

This pretty much highlights the changes, but sadly took me a few hours to figure out.  I went down the jQuery route successfully, but decided to keep these functions from requiring jQuery to be loaded.  I also wasted some time on using RegEx which was for naught due to the XML namespace.

 

Downloading the Code

One thing I’ve noticed with my other blog posts has been issues related to getting the code downloaded.  So I’ve placed everything out on GitHub and hopefully this will be more convenient for everyone.

https://github.com/paul-way/JCL

 

Finally, I hope this helps you with your IE 10 future and your fancy new Surface (I wish I preordered one).  Let me know your thoughts by either commenting at blog.customereffective.com or tweeting me (@paul_way).  Coming 10/26…

Show Buttons
Hide Buttons