web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

XMLHttpsRequest 500 Internal Server error

(0) ShareShare
ReportReport
Posted on by 2,665

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

I have the same question (0)
  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi roxanna,

    Are  you getting error when testing on Rest Builder? Can try deleting the script from webresouce and re add again.

    Thanks

    Justin Jose

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans