how to get current logged in user and email and department in service now

karna daripally
Kilo Contributor

fshnfgnx

5 REPLIES 5

Logan Poynter
Mega Sage
Mega Sage

Hello,

User:
gs.getUser()

Email:
gs.getUser().getEmail()

Department: 
You would have to do a GlideRecord .get query on sys_user using gs.getUserID() to return the department

var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
gs.print(gr.department);

 

Please mark my answer as correct/helpful if it has helped you.

Thanks,
Logan
--
LinkedIn

Preeti Singh
Kilo Contributor

Hi Karna,

 

You can write onLoad client script to achieve this requirement.

function onLoad() {

if (g_form.isNewRecord()) {
g_form.setValue('caller_id', g_user.userID);
g_form.setValue('email', g_form.getReference('caller_id').email);
g_form.setValue('department', g_form.getReference('caller_id').department);
}
}

 

Please mark my answer as correct/helpful if it has helped you.
 

Thank you!

 

 

arun38
Tera Contributor

 g_form.getreference('caller_id);

 g_form.getreference('caller_id).email;

 g_form.getreference('caller_id).department;

Gulzar Manuja2
Kilo Guru

Hi Karna,

I see a few responses where it has been suggested to use getReference function. Please note that getReference won't return you results on Service Portal. Kindly select and proceed with the suggested solutions accordingly. 

Please mark this response as Helpful if it helps !!!