Hello,
Here I'm fetching data using javascript FetchXML. and It works fine in an unmanaged package but it gives me an error in a managed package.
function getAPIRecordsByFetchXML() { try { var entityNameApi = "accounts"; var fetchData = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="account"><attribute name="name" /><attribute name="primarycontactid" /><attribute name="telephone1" /><attribute name="accountid" /><order attribute="name" descending="false" /><filter type="and"><condition attribute="name" operator="eq" value="Account1" /></filter></entity></fetch>'; var data; var serverUrl = "abc123.crm.dynamics.com"; var req = new XMLHttpRequest(); req.open("GET", serverUrl + "/api/data/v8.0/" + entityNameApi + "?fetchXml=" + fetchData, false); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\""); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { data = JSON.parse(this.response); } else { var error = JSON.parse(this.response).error; alert(error.message); } } }; req.send(); return data; } catch (e) { alert(e.message); } }
Error:
Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://abc123.crm.dynamics.com/api/data/v8.0/accounts?fetchXml=%3Cfetch%20version=%221.0%22%20output-format=%22xml-platform%22%20mapping=%22logical%22%20distinct=%22false%22%3E%20%20%3Centity%20name=%22account%22%3E%20%20%20%20%3Cattribute%20name=%22name%22%20/%3E%20%20%20%20%3Cattribute%20name=%22primarycontactid%22%20/%3E%20%20%20%20%3Cattribute%20name=%22telephone1%22%20/%3E%20%20%20%20%3Cattribute%20name=%22accountid%22%20/%3E%20%20%20%20%3Corder%20attribute=%22name%22%20descending=%22false%22%20/%3E%20%20%20%20%3Cfilter%20type=%22and%22%3E%20%20%20%20%20%20%3Ccondition%20attribute=%22name%22%20operator=%22eq%22%20value=%22Account1%22%20/%3E%20%20%20%20%3C/filter%3E%20%20%3C/entity%3E%3C/fetch%3E'
Please suggest me how to solve this error?
*This post is locked for comments
Hi Chaaya Patel,
The FetchXML needs to be in a format usable by the Web API service endpoint.
See: https://www.hbs.net/blog/march-2017/using-fetchxml-in-web-api-queries-via-javascript-f
Hope this helps.
Hi,
You are posting as "Get" Method, I think that is wrong use post method. Follow this -
alexanderdevelopment.net/.../fetchxml-jquery-in-a-dynamics-crm-2011-web-resource
Hi,
Have you checked the url if it's pointing to the correct url? Also, make sure you have the same entity & attributes.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156