Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Error with JavaScript fetchXml is not a function

(0) ShareShare
ReportReport
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,325 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,325 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans