web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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!

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

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

  • Joao Santos Profile Picture
    25 on at

    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!

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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.

  • Verified answer
    Joao Santos Profile Picture
    25 on at

    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!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans