Javascript to get the User Name in CRM 2013/2015

Hi,
 
We used to write soap call method for getting the user name on the form in JavaScript.
We used to get User Id by using the following line.

Xrm.Page.context.getUserId();

Now in the same way, we can also get the logged in user name.

Xrm.Page.context.getUserName();

Use the following code to set the lookup field in JavaScript.

var setUserLoopUp = new Array();
setUserLoopUp[0] = new Object();
setUserLoopUp[0].id = Xrm.Page.context.getUserId();
setUserLoopUp[0].name = Xrm.Page.context.getUserName();
setUserLoopUp[0].entityType = ‘systemuser’;
// Set the look up field.
Xrm.Page.getAttribute(“LookupField”).setValue(setUserLoopUp);
 
For more information on Setting and Getting Lookups

Hope this helps.


Happy CRM’ing
Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s