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.

Client Script

Shrabanti
Tera Contributor

Hello Team
sys_user table have some uers who has two profile with same name one with normal user id like 123xxx and other profile is with hyphen userid like aba-234 

user are login servicenow with normal user id .
in a catalouge item one varible need to populate name of current login user which is associated with hyphen id
i wrote that scrip but not working 

var name= g_user.getFullName();
   alert(name);// showing name of login user
   var gr=new GlideRecord('sys_user');
   gr.getEncodedQuery('active=true^user_nameLIKE-');
   gr.addQuery('name',name);
   gr.query();
   if(gr.next()){
    g_form.setValue('owner_of_lz_groups_paa_account',gr.sys_id);
13 REPLIES 13

ShubhamGarg
Kilo Sage

Hello @Shrabanti ,

Considering this variable of type reference to sys_user table, you can set default value to -

 

 

javascript:gs.getUserID();

 

Replace : with :

 It will show logged in user's name.

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

hello
i want to populate that second user profile with hyphen userid not that login user one

Abhishek_Thakur
Mega Sage
Mega Sage

Hello @Shrabanti ,

You can paste the below code in the default value section of the variable.

javascript: gs.getUserDisplayName();

Please accept my solution and give thumbs up, if it helps you.

Abhishek_Thakur
Mega Sage
Mega Sage

Hello @Shrabanti ,

 

You can refer the below screenshot, that is definitely going to help you.

Default value.png

By default.png

 

Please accept my solution and give thumbs up, if it helps you.