Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to add users from watch list to the CC of email notification

Rutusha
Tera Contributor

Hi all,

I have a requirement where i need to add all the watchlist users to the CC of email notification.

I have written the mail script but not getting the outcome.

Could someone help me on this.

Tried putting logs.

Log inside while loop is not coming.

 

function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
if(!current.watch_list.nil()){
var watcherIds = current.watch_list.toString().split(',');
gs.info("watcherIds-->"+watcherIds);
var user = new GlideRecord("sys_user");
user.addQuery('sys_id','IN',watcherIds);
user.addQuery('email','!=','');
user.query();
gs.info('test is' +"sys_idIN" +current.watch_list+"");
while(user.next()){
gs.info('user in the watchlist are' +watcherIds);
email.addAddress('cc', user.email, user.displayName());
}
}
})(current, template,email, email_action, event);
 
@Ankur Bawiskar Could you please help me here
10 REPLIES 10

Hi @Ankur Bawiskar 

I tried with log statements.

log statement inside while loop is not coming.

Apart from that I also tried if the query is returning correct result or not by adding log with the filter query.