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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get value of systemuser entity ?

(0) ShareShare
ReportReport
Posted on by

Hi all !

I have a problem with getting the value from systemuser entity on save event. I am sharing my code below so maybe you can correct.

It says "Bad Request" when i click on save.

function autoFillSubject() {
	debugger;
	var FormType = Xrm.Page.ui.getFormType();
	if ( FormType != "1" || FormType == null ) {
	return; }

var userid = Xrm.Page.context.getUserId();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/systemusers("+userid+")?$select=_territoryid_value", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var _territoryid_value = result["_territoryid_value"];
            var _territoryid_value_formatted = result["_territoryid_value@OData.Community.Display.V1.FormattedValue"];
            var _territoryid_value_lookuplogicalname = result["_territoryid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
	
	var regarding = Xrm.Page.data.entity.attributes.get("regardingobjectid");
	var regardingVal = regarding.getValue();
		regardingVal = regardingVal[0].name;
	
	var date = Xrm.Page.data.entity.attributes.get("scheduledstart");
	var dateVal = date.getValue();

	var year = dateVal.getFullYear()+"";
	var month = (dateVal.getMonth()+1)+"";
	var day = dateVal.getDate()+"";
	var dateFormat = day + "/" + month + "/" + year;
	
	var subject = Xrm.Page.data.entity.attributes.get("subject");
		subject.setValue(regardingVal + "-" + _territoryid_value_formatted + "-" + dateFormat);
		
		} else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();
	
}


*This post is locked for comments

I have the same question (0)
  • Verified answer
    Royal King Profile Picture
    27,686 on at
    I think issue is guid bracess ({}). Before passing user guid remove the braces from the guid. like 
    userid.slice(1,-1) this will remove the braces. 
  • Community Member Profile Picture
    on at

    Yes you are right, thanks ! But now im getting another error like below.

    8461.ss.png

  • Royal King Profile Picture
    27,686 on at

    This message is shown if this user already has another appointment at same time. SO check the existing appointment with date and time.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/blogs/post/?postid=%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))," - Too many )'s.