Why gs.getUserDisplayName() or gs.getUser().getFullName() returning 'System' as the username
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 06:11 PM
I'm using gs object in email notification script to get the currently logged-in userName but it is always returning 'System' as the name.
Email script code:
CurrentUserName();
function CurrentUserName(){
var logged_in_user = gs.getUser().getFullName(); // same results for gs.getUserDisplayName()
template.print('Current User:' + logged_in_user);
}
Email notification code:
${mail_script:email_script_name}
Does anyone know why is this happening ? Am I missing anything here ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 07:37 PM
Reach,
I won't lie, and I'm going to make a guess, but perhaps the email notification runs as the System account to ensure it has the proper rights. To help with this, you might need to have it create an Event, and feed that information in as a parameter value. Such as via:
http://wiki.servicenow.com/index.php?title=Events_and_Email_Notification
-Damian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 10:07 PM
Rather than doing this in the email notification, if you are triggering this email via an event, I suggest that you pass the logged in user name with the event call itself. It will look like this:-
gs.eventQueue("<event_name>", current, gs.getUserID(), gs.getUserName());
You can replace these parameter with whatever you want. In the email notification, you can use the parameters like this:-
${event.parm1} or ${event.parm2}
Thanks & Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 10:58 AM
Thanks Damian and Hari. I switched to events to trigger email and works now . Thanks a lot !!!
Thanks,
Reach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 11:02 AM
Reach,
Glad it worked! It's always good to understand the difference between the generic notification and an event driven one. Soon enough the mail_scripting gets even more fun. lol.
-Damian