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

  • Suggested answer
    Justinjose Profile Picture
    Justinjose 2,707 on at
    RE: XMLHttpsRequest 500 Internal Server error

    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans