Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Error with JavaScript fetchXml is not a function

Posted on by 25

Hi there,

I'm struggling to troubleshoot this internally, so reaching out to the community.

We have an issue related to a Ribbon button on a Form entity, which is working in Sandbox environments but not in Production.

The functionality is exactly the same on all instances, so we are wondering what the issue might be.

It seems to be related to the fetchXml function which has been working for years, but not not working in one instance.

The function is getting an error "fetchXml is not a function".

Here's an example below: we've generating a Word Document from a Document Template, and the code is getting the Template Id, which calls another function (which is the one failing based on the Consule log):

function getTemplateId() {
var id = null;
var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='documenttemplate' >" +
"<attribute name='documenttemplateid' />" +
"<attribute name='name' />" +
"<attribute name='documenttype' />" +
"<order attribute='name' descending='false' />" +
"<filter type='and' >" +
"<condition attribute='name' operator='eq' value='Buyers Grid Summary' />" +
"</filter>" +
"</entity>" +
"</fetch>";

fetchXml(
"documenttemplates",
fetch,
function(results) {
if (results.value.length > 0) {
id = results.value[0].documenttemplateid;
}
},
function(results) {},
false
);
return id;
}

Any help would be greatly appreciated! Thank you in advance!

  • Verified answer
    Joao Santos Profile Picture
    Joao Santos 25 on at
    RE: Error with JavaScript fetchXml is not a function

    This has now been resolved and the issue (although only happening in a couple of environments) has been fixed.

    Basically we've changed the Function name and updated it with the FetchXml and defined the fetch Function that was being called in the same Function.

    Thanks Andrew Butenko for your thoughts anyway, it definitely helped looking into it more closely!

  • Verified answer
    a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Error with JavaScript fetchXml is not a function

    If it's in the same webresource to be honest I have no idea. I would highly recommend to put breakpoints in the code before the place where the function is called from and check if fetchXml function is available.

  • Joao Santos Profile Picture
    Joao Santos 25 on at
    RE: Error with JavaScript fetchXml is not a function

    Hi Andrew,

    Thanks a lot for your feedback.

    Yes, the fetchXml function is on the same WebResource, so I was expecting it to work. Plus it works in our Development instance but not in Prod, even thought the code is the same. Any ideas?

    The Function is stated on the Web Resource as per below:

    function fetchXml(entitypluralname, query, onRetrieveSuccess, onRetrieveError, isAsyncRequest) {

       var req = new XMLHttpRequest();

       req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.1/" + entitypluralname + "?fetchXml=" + query, isAsyncRequest);

       req.setRequestHeader("OData-MaxVersion", "4.0");

       req.setRequestHeader("OData-Version", "4.0");

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

       req.onreadystatechange = function() {

           if (this.readyState === 4) {

               req.onreadystatechange = null;

               if (this.status === 200) {

                   onRetrieveSuccess(JSON.parse(this.response));

               } else {

                   onRetrieveError(JSON.parse(this.response));

               }

           }

       };

       req.send();

    };

    Thank you!

  • a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Error with JavaScript fetchXml is not a function

    Hello,

    I see fetchXml function referenced in your code. Is it in the same webresource or in the other?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans