gs.getUserID() not showing current user instead its showing "system" for every user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 04:20 PM
I have an email script that checks the current logged in user's role and then generates a link based on the role.
If the user has sn_hr_core.basic role, the user will be redirected to the native view HR case.
If the user is an ESS user(No itil or HR role) it will be redirected to the ESS Portal view.
Below is the script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//var instance_name = gs.getProperty('glide.servlet.uri');
var link ="";
var currentUser = gs.getUserID();
gs.info("currentUser1+"+currentUser); // showing as system for every user
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', currentUser);
gr.addQuery('role', 'f25370019f22120047a2d126c42e7061'); //checks sn_hr_core.basic
gr.query();
if(gr.next()) {
gs.info("hr");
link = gs.getProperty("glide.servlet.uri") + 'sn_hr_core_case.do?sys_id=' + current.sys_id;
template.print('<strong> <a href="' + link + '">' + current.number + '</a> </strong>\n');
}
else{
gs.info ("ess");
link = gs.getProperty("glide.servlet.uri") + 'hr?id=ticket&table=sn_hr_core_case&sys_id=' + current.sys_id + '&view=sp#hr';
template.print('<strong> <a href="' + link + '">' + current.number + '</a> </strong>\n');
}
})(current, template, email, email_action, event);
For some reason it's not getting the correct current logged in user's value. as gs.getUserID() not showing current user instead its showing "system".
Any thoughts would be much appreciated !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2020 09:17 AM
The requirement is if User receives an email and if he tries to click on the hyperlink in the email - Based on his role page should open:
a) If an end user opens this it should redirect to portal view of the ticket
b) If user with hr basic role opens then native view of the ticket should get opened
So instead of implementing it through email script can we use SPEntryPage script include enhancement to control the dynamic redirections. Any suggestion on this..