Hi,
I have a script working fine in my dev, test & prod. Recently, the script is throwing 500 internal server error(userRequest.status) in dev but working fine in both test & prod environments.
How do I troubleshoot 500 internal server errors? I've built the rest query using REST builder and the same url works fine for test & prod except for dev.
I did add new fields to dev form on which this script is failing.. but those fields have no usage in the script. Other than that the form is same as is as test & prod.
Here is the script that I am having trouble with:
function getUserCountry(userId) { debugger; var createdOn=Xrm.Page.getAttribute("createdon").getValue(); if(createdOn!=null) { return; } var serverUrl = Xrm.Page.context.getClientUrl(); //var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc"; var ODataPath = serverUrl + "/api/data/v8.0"; var userRequest = new XMLHttpRequest(); userRequest.open("GET", ODataPath + "/SystemUsersSet(guid'" + userId + "')?$select=new_country", true); 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.send(); if (userRequest.status === 200) { var retrievedUser = JSON.parse(userRequest.responseText).d; var country = retrievedUser.new_country; // new_country is the lookup field name inside user entity return country; } else { return "error"; } } var owner = Xrm.Page.getAttribute("ownerid").getValue(); if(owner!=null) { var ownerId = owner[0].id; var country = getUserCountry(ownerId); if(country!=null) { var countryValue = new Array(); countryValue[0] = new Object(); countryValue[0].id = country.Id; countryValue[0].name = country.Name; countryValue[0].entityType = country.LogicalName; Xrm.Page.getAttribute("new_country").setValue(countryValue); }
Thanks for any help!
*This post is locked for comments