HI,
we've just upgraded to CRM 2016 from 2015 on prem. This below script was working fine until 2015.
I've modified the script to use the new api format. But the XMLHttprequest returns 400 no matter what changes I do.
I've built the odata query from CRM Rest builder tool in which I don't have option for adding filters. So, the filter part was written by me and I am not sure if the filter is the issue or something else. Can somebody please look into this and guide me? Thanks.
function countryNumber(countryId) { var serverUrl = Xrm.Page.context.getClientUrl(); var ODataPath = serverUrl + "/api/data/v8.0/new_countries?$select=new_countrynumber&$filter=new_countryId eq (guid\'" + countryId + "\')"; var userRequest = new XMLHttpRequest(); userRequest.open("GET", encodeURI(ODataPath), false); userRequest.setRequestHeader("OData-MaxVersion", "4.0"); userRequest.setRequestHeader("OData-Version", "4.0"); userRequest.setRequestHeader("Accept", "application/json"); userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8"); userRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); userRequest.send(); if (userRequest.status === 200) { var retrievedUser = JSON.parse(userRequest.responseText); if (retrievedUser != null && retrievedUser.results.length > 0) { var countryNumber = retrievedUser.results[0].new_countrynumber; return countryNumber; } } }
*This post is locked for comments