locked
FetchXML HttpRequest object is constructed differently inside a webresource compared to outside. Anyone know why? RRS feed

  • Question

  • I'm wondering if anyone can shed any light on the below:

    I have a html webresource which is hosted on an entity form. The resource is using Jscript to create and execute a fetchXML request which aggregates up some data from child records.

    The HTML page when executed as a stand alone page performs perfectly - retrieving the data and summing up nicely. When I host the resource in the entity form though, it fails silently. No big blow up or anything, but it doesn't render the fetchxml results.

    Analysis using the F12 IE tools shows me that when I create the fetchXML request object using

     var req = new XMLHttpRequest();

    When rendering the html page stand-alone the req object is of type "DispHTMLXMLRequest", wheras when the html is executed from within the webresource on the entity form, the req object is of type "XMLHttpRequest". The latter seems to be unable to parse the XML results, even though it is exactly the same XML response from the server. I get an "unspecified error" when the success callback function tries to render the responseXML. I've also tried to call parse.XML(req.response) - this also gives an "unspecified error"

    I've used fiddler to confirm that the fetchXML is executing successfully in both cases, and returning results. The responses from the crm webservices are identical.

    The last thing that I've noticed is that if I use IE tools to make the browser run in IE8 document mode, then the page renders correctly both as a stand alone page and as an embedded web resource. (The req object is created as DispHTMLXMLHttpRequest rather than an XMLHttpRequest)

    Can anyone explain why the constructor of the req var acts differently when running in a webresource to what it does as a stand alone html page? Is there a way that I can explicitly control the behaviour of the constructor?

    Additionally - can anyone explain why IE8 seems to work for the embedded webresource, wheras all IE versions above 8 fail?

    I'll re-iterate - this is not an issue with the fetchXML itself - the request to CRM succeeds every time, and responds perfectly. It's an issue with how the Jscript XMLHttpRequest is constructed in different scenarios, and how that Jscript XMLHttpReqeust object is able to parse the results.


    Paul Dowman, CRM Developer

    Monday, April 13, 2015 11:18 AM