Monday, 21 September 2015

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

No comments:

Post a Comment