- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 06:01 AM
Hello,
I'm working on an email script that should include a link to the incident ticket if the user role is 'itil' and if anything else they'll be directed to the ESS portal.
My if/else statement is working. But for some reason .hasRole is always 'true'. I thought it was because I was logged in as an admin, but when I impersonate a user with no roles, I still only get a notification with the incident link.
Can anyone spot what I'm getting wrong?
Thanks!
var currentUser = gs.getUser();
var link = current.getLink();
template.print(currentUser.hasRole('itil'));
if (currentUser.hasRole('itil')) {
template.print('<a href="' + link + '">GO TO INCIDENT</a>');
}
else {
template.print('<a href="https://dev.service-now.com/ess">GO TO PORTAL</a>');
}
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 10:28 AM
just to be clear you want to show go to Incident only when caller_id user has itil role?
var currentUser = gs.getUser().getUserByID(current.caller_id).hasRole('itil');
var link = current.getLink();
template.print(currentUser);
if (currentUser){
template.print('<a href="' + link + '">GO TO INCIDENT</a>');
}else{
template.print('<a href="https://dev.service-now.com/ess">GO TO PORTAL</a>');
}
if you want to get other field than you need to change current.u_requested_for in belwo code.
var currentUser = gs.getUser().getUserByID(current.u_requested_for).hasRole('itil');
var link = current.getLink();
template.print(currentUser);
if (currentUser){
template.print('<a href="' + link + '">GO TO INCIDENT</a>');
}else{
template.print('<a href="https://dev.service-now.com/ess">GO TO PORTAL</a>');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 08:47 AM
How this emails are getting triggered? From event? if yes, then try passing current user sys_id in parm2 of the event and in script include query sys_user_has_role table with that sys_id.
because some of the process in SNOW are processed using system as user instead of logged in user. for example in workflow, after timer activity the updates will be tagged as updated by system. same with events and notification.
I suspect this might be the issue.
just to validate add log statement to print current logged in user:
gs.log(gs.getUserName(),"Notification_user"); // check logs with source as Notification_user
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 10:02 AM
This is for incident notifications. So, the email script will be added to the notifications for incident. Which may an issue when it comes to testing.