Access current user within email notification script (Geneva)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 09:10 AM
Within my Geneva instance, attempting to extract the current user name within an email notification script resulted as the user returning as "System" and not "John Doe". Within my personal instance (running Istanbul), the same script displays the full user name (e.g. John Doe).
Here are a few variations of code used in both instances:
- Geneva = "System"
- Istanbul = "John Doe"
// GlideSystem method call
template.print("user : " + gs.getUserDisplayName());
// GlideSystem user object ref.
var u = gs.getUser();
template.print("user : " + u.getDisplayName());
While searching the SNOW community boards, I ran across the following piece of code.
var user = gs.getUser().getUserByID(current.sys_updated_by);
template.print("user : " + user);
In Geneva, it extracted an actual user name (e.g. John Doe), but I was informed by a colleague that it was extracting the user who performed the most recent update (current.sys_updated_by) and not the actual current user running the script.
Could this be version related or perhaps I'm barking up the wrong tree? Also, where can I find more information regarding variables associated with "current"?
- Leo
P.S. I gathered my info from the following sources:
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 02:45 AM
Hi Leo,
Whenever the notification is triggered the system checks from whose session it was triggered. If it is some user then username will be some valid user in servicenow. But if it is system then it will show the system as username
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 07:26 AM
Hi Ankur,
When the script the displayed "System", I arrived to the same conclusion, ...the script was being executed by the application/system and not the current user. That makes sense and I'm willing to accept it, but the inconsistency between system versions left me confused and worried. It seems that code setup to work in one version will begin to work differently in the other, causing unintended problems.
Perhaps the best solution would be to spend a few hours reviewing changes between ServiceNow versions. Finding the time to do so is another challenge.
Thanks for taking the time to reply,
- Leo