Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to get value of systemuser entity ?

Posted on by Microsoft Employee

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

  • Royal King Profile Picture
    Royal King 27,686 on at
    RE: How to get value of systemuser entity ?

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get value of systemuser entity ?

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

    8461.ss.png

  • Verified answer
    Royal King Profile Picture
    Royal King 27,686 on at
    RE: How to get value of systemuser entity ?
    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. 

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans