Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to populate logged user name in reference field

Arun91
Tera Contributor

Hi,

In incident form we have field called caller_id. The person who logged in their name should auto populate in the caller_id field. Once he removed the name then in the list it should show the logged in user name first followed by the list of user based on alphabetical order. How we can achieve this. Could anyone help me on this.

 

Thanks in advance

3 REPLIES 3

Sohail Khilji
Kilo Patron

Hi @Arun91 ,

 

You can do this by setting the default value of the field from dictonary to > javascript:gs.getUserID()

 

and to show the users in alphabatical order  :

use attribue > ref_ac_order_by=name

 

i hope this helps...

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

If we click on x mark in the reference field, then it should display the logged in username first followed by the list of users from sys_user table. How we can achieve this.

Manikmodi16
Tera Guru

Hi, 

You can create an OnLoad Client script on the incident form with the below code:

 

var userID = g_user.userID;

g_form.setValue('caller_id', userID);

 

This will set the value of the caller_id field with the currently logged in user.

 

Thanks,

Manik Modi

 

If you find this helpful, please mark this reply as the solution. Thanks!