Why gs.getUserDisplayName() or gs.getUser().getFullName() returning 'System' as the username

Aparna Sharma
ServiceNow Employee
ServiceNow Employee

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 ?

4 REPLIES 4

nullreturned
Kilo Guru

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


harikrish_v
Mega Guru

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


Aparna Sharma
ServiceNow Employee
ServiceNow Employee

Thanks Damian and Hari. I switched to events to trigger email and works now . Thanks a lot !!!



Thanks,


Reach


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