Announcements
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!
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!
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.
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!
Hello,
I see fetchXml function referenced in your code. Is it in the same webresource or in the other?
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156