How to get ITIL group managers email using Notification email script.

Neelavathi M
Tera Contributor

Hi All,

I have a requirement to send the Notification to ITIL Group manager , if user is added to the Group which has ITIL+other role .

 

this Notification created on the sc_req_item table based on condition.

 

NeelavathiM_0-1690532195719.png

here "select group" has 2 roles (itil + other rol'e)  ,if user added to any one of the group he will get "itil" access will hence that time notification has to trigger to "ITIL Role group Manager" ,so i am not able select the  ITIL Role group manager email from the "Who will receive" tab, so can that be achieved using the Email script to get the "ITIL Role group managers email" so that i can add to body of the Notification.

Please suggest how to achieve this

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi here is the example to do that, in you email script you need to get the group name , if you have a variable where group name is stored, you can get group sysid using variable value,

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

var getManagerEmail = '';

//var managerEmail = current.variables.variablename; // use this line if you have group name stored in variable
var grp = new GlideRecord('sys_user_group');
grp.addQuery('sys_id','c6c828c453751300ba3dddeeff7b1219');
grp.query();
if(grp.next())
{
getManagerEmail = grp.manager.email;
gs.info(getManagerEmail );
email.addAddress("bcc",getManagerEmail);
}

})(current, template, email, email_action, event);

Regards
Harish

View solution in original post

2 REPLIES 2

Harish KM
Kilo Patron
Kilo Patron

Hi here is the example to do that, in you email script you need to get the group name , if you have a variable where group name is stored, you can get group sysid using variable value,

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

var getManagerEmail = '';

//var managerEmail = current.variables.variablename; // use this line if you have group name stored in variable
var grp = new GlideRecord('sys_user_group');
grp.addQuery('sys_id','c6c828c453751300ba3dddeeff7b1219');
grp.query();
if(grp.next())
{
getManagerEmail = grp.manager.email;
gs.info(getManagerEmail );
email.addAddress("bcc",getManagerEmail);
}

})(current, template, email, email_action, event);

Regards
Harish

Hi , thanks for your help,  the same script i  have used in Business rule and uses gs.eventQueue to trigger the notification and it working as expected.

gs.eventQueue('emailToITILManager', current, getManagerEmail);