Help Adding Multiple Recipients to CC via Mail Script

apjohn2
Mega Sage

Hi all,

Looking for help w/ adding multiple users to CC in a notification. I am using a mail script w/ the email.addAddress() function and I am getting the right output (per logs) but the mail doesn't appear to be going to the listed users.

Scenario: When a requested item is awaiting approval, sometimes the approver doesn't respond. If the requester (or anyone really) leaves a comment we have it so a notification including that comment goes to both the requested-for user and the current approver(s) for the requested item.

This is proving insufficient in our org and I need to add our IT Service Desk group members to the CC on these notifications so they can be more proactive in responding when people see that things are hung up.

The mail script I'm using is thus:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
	
	var sdesk = []; // declare array to push IT Service Desk group member emails into
	var sd = new GlideRecord('sys_user_grmember');
	sd.addQuery('group','e3988a82dbda3e00641b572e5e9619bb'); // sys_id of the IT Service Desk group
	sd.query();
	while (sd.next()) {
		sdesk.push(sd.user.email);
	}	
	gs.log(sdesk.toString());
	email.addAddress("cc",sdesk.toString(),"IT Service Desk");
	
})(current, template, email, email_action, event);

The logs show the correct users, but (having added the 'Copied' field to the sent sys_email form) the recipients are not showing up in the email.

Thanks in advance for any tips here!

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Try this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
	
	var sd = new GlideRecord('sys_user_grmember');
	sd.addQuery('group','e3988a82dbda3e00641b572e5e9619bb'); // sys_id of the IT Service Desk group
	sd.query();

	while (sd.next()) {
                email.addAddress("cc",sd.user.email,"IT Service Desk"); 
	}	
	
})(current, template, email, email_action, event);

 

For Reference see the last example script on the below link where users are getting added to CC from watch list. 

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/script/server-scripting/referenc...

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

View solution in original post

5 REPLIES 5