- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 07:38 AM
Hello,
I have configured a notification that will be sent to the user opening a request on our Service Catalog.
The requirement is that if the user opening the request has no roles, he should be redirected to our ESS portal. If the user opening the request has roles(ITIL) he should be redirected to the normal view. I have the following code:
attachLink();
function attachLink() {
//Check for requestor's role
var userObj = gs.getUser().getUserByID(current.requested_for.user_name);
if (userObj.hasRole('itil')) {
template.print('<a href="/nav_to.do?uri=sc_req_item.do?sys_id='+current.sys_id+'">' + current.number + '</a>');
}
else {
template.print('<a href="/ess/ess_ritm.do?uri=sc_req_item.do?sys_id='+current.sys_id+'">' + current.number + '</a>');
}
}
Unfortunately the code is not working, it's not checking if the user has ITIL role or not and all users are redirected to '<a href="/ess/ess_ritm.do?uri=sc_req_item.do?sys_id='+current.sys_id+'">' + current.number + '</a>');
What do I have to do to make the above code work?
I have limited experience with scripting therefore any ideas will be much appreciated!
Alex
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 08:13 AM
I would make sure you're getting the right requested for user. It looks like this notification may be firing from the sc_req_item table, but there is no requested_for field on that table. You may need to do current.request.requested_for;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 08:13 AM
I would make sure you're getting the right requested for user. It looks like this notification may be firing from the sc_req_item table, but there is no requested_for field on that table. You may need to do current.request.requested_for;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 10:42 AM
Brad,
That did the trick! Thank you very much for your fast response!
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 07:49 AM
Hi Alexandru,
I'm going to resurrect this thread as I'm having to do something very similar and instead of the ESS portal I have Service Portal. My first question is, where do you add the below script?
attachLink();
function attachLink() {
//Check for requestor's role
var userObj = gs.getUser().getUserByID(current.request.requested_for);
if (userObj.hasRole('itil')) {
template.print('<a href="/nav_to.do?uri=sc_req_item.do?sys_id='+current.sys_id+'">' + current.number + '</a>');
}
else {
template.print('<a href="/ess/ess_ritm.do?uri=sc_req_item.do?sys_id='+current.sys_id+'">' + current.number + '</a>');
}
}
If it's for a request notification, would you add this in the relevant notification/template or did you add it as a 'notification email script' and referenced in the notification where it says 'Click here to view request' ?
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 01:25 AM
You can ignore my question as I've managed to solve the issue.
Cheers!