notification trigger to different place

rah dev
Tera Contributor

Hi Everyone,

I am trying to implement a requirement in ServiceNow email notifications where:

If the recipient user belongs to this group, the incident link should open in SOW Workspace.

If the user does not belong to this group, the link should open in Classic Backend view.

I am using the following Email Script:

(function runMailScript(current, template, email, email_action, event) {

var instanceUrl = gs.getProperty('glide.servlet.uri');
var sysId = current.sys_id.toString();
var number = current.number.toString();
var helpdeskGroupId = '477a05d153013010b846ddeeff7b1225';

// Default: Classic view
var recordLink = instanceUrl + 'incident.do?sys_id=' + sysId;

var recipientEmail = (email.address || '').toString();

var userGr = new GlideRecord('sys_user');
userGr.addQuery('email', recipientEmail);
userGr.setLimit(1);
userGr.query();

if (userGr.next()) {

var gmGr = new GlideRecord('sys_user_grmember');
gmGr.addQuery('user', userGr.sys_id);
gmGr.addQuery('group', helpdeskGroupId);
gmGr.setLimit(1);
gmGr.query();

if (gmGr.next()) {
recordLink = instanceUrl + 'now/sow/record/incident/' + sysId;
}
}

template.print(
'Incident: <a href="' + recordLink + '" style="color:#0070d2; font-weight:bold;">' + number + '</a>'
);

})(current, template, email, email_action, event);
The issue is:
Even when the user belongs to this group, the notification link still opens in Classic View instead of SOW Workspace.

 

Has anyone implemented a similar requirement successfully?
Is there a better way to identify the actual recipient/logged-in user in Notification Email Scripts?

Any guidance would be appreciated.

0 REPLIES 0