Email notification is not working using email script

mahesh105
Tera Contributor

I am trying to add group on email notification using email script. but it is not sending notification to group members.

Please refer the code and suggest me :

 

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

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery("request", current.request.sys_id);
ritm.query();
if (ritm.next()) {
var loc = current.u_item_for.location.name;   //user location
gs.log("xyz" + loc);

}
var emails = [];
var userName = [];
var gr = new GlideRecord('sys_user_grmember');
if (loc.includes('Operations') && loc.slice(-2) == 'MA') {    //if users location contain Operations and Ma notification goes to ServiceNow.Application.Approver.Metrc.MAGrowCompliance group.

gr.addQuery("group.name", "ServiceNow.Application.Approver.Metrc.MAGrowCompliance"); 
gr.query();
while (gr.next()) {
emails.push(gr.user.email.toString());
userName.push(gr.user.toString());
email.addAddress("cc", gr.user.email.toString(), gr.user.getDisplayValue());
gs.info("Tanuj" + emails.toString());
gs.info("Mahesh" + userName.toString());
}

6 REPLIES 6

@Upender Kumar : Tried this solution but still it is not sending email notification

Ankur Bawiskar
Tera Patron
Tera Patron

@mahesh105 

are you sure the user you are adding in CC is

1) active and not locked out

2) has email field populated in user record

3) notification preference is enabled

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader