how to get current logged in user and email and department in service now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 09:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 10:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 11:26 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 11:44 PM
g_form.getreference('caller_id);
g_form.getreference('caller_id).email;
g_form.getreference('caller_id).department;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 11:49 PM
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 !!!