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.

User details on client script

ceraulo
Mega Guru

Hello!

How do I get other current user details (example location, department, phone) in a client script?

Thank you.

1 ACCEPTED SOLUTION

Shweta KHAJAPUR
Tera Guru

Hi,

Write below code in Display BR

var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
g_scratchpad.location = gr.location.name;
g_scratchpad.department = gr.department.name;
g_scratchpad.number = gr.mobile_phone;

Write Below code in onLoad client script

g_form.addInfoMessage(g_scratchpad.location); 
g_form.addInfoMessage(g_scratchpad.department); 
g_form.addInfoMessage(g_scratchpad.number); 

View solution in original post

9 REPLIES 9

Shweta KHAJAPUR
Tera Guru

Hi,

Write below code in Display BR

var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
g_scratchpad.location = gr.location.name;
g_scratchpad.department = gr.department.name;
g_scratchpad.number = gr.mobile_phone;

Write Below code in onLoad client script

g_form.addInfoMessage(g_scratchpad.location); 
g_form.addInfoMessage(g_scratchpad.department); 
g_form.addInfoMessage(g_scratchpad.number); 

It works! Thank you so much.

I have one more problem. I want to populate these values to the additional comments field on load.

I tried the code below but it isn't working.

g_form.comments = g_scratchpad.location + " " + g_scratchpad.department + " " + g_scratchpad.number;

Try as below,

g_form.setValue('comments', g_scratchpad.location + " " + g_scratchpad.department + " " + g_scratchpad.number);

Please mark my answer as correct and close the thread.

Try like this also,

var detail = g_scratchpad.location + " " + g_scratchpad.department + " " + g_scratchpad.number;
g_form.setValue('comments',detail);