Notifications
Announcements
No record found.
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
Hi,
have a look at this:
"Filter records based on single-valued navigation property"
msdn.microsoft.com/.../gg334767.aspx
Your "path" should probably look more like this:
var ODataPath = serverUrl + "/api/data/v8.0/new_lapcounties?$select=new_countynumber&$filter=new_lapcounty/new_lapcountyid eq " + countyId;
You don't need that guid' etc, btw
Hi there,
Save yourself the headache and install the CRM Rest builder tool.
Then you can see what you're doing wrong.
var ODataPath = serverUrl + "/api/data/v8.0/new_lapcounties?$select=new_countynumber&$filter=new_lapcountyid eq '" + countyId + "'";
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2