Javascript to get the User Name in CRM 2013/2015

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.


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


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.
For more information on Setting and Getting Lookups

Hope this helps.

Happy CRM’ing

Leave a Reply

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

You are commenting using your 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