add a user/group in CC of an email

NiloferS
Tera Contributor

I have a custom table and the form as below:

NiloferS_0-1718355405559.png

We want Recipient in cc of email notification. I have written a email script as below:

NiloferS_1-1718355581332.png

NiloferS_2-1718355839398.png

Its not working as expected.

The email template has nothing mentioned in it, so its not overriding my code.

Note: this email notification is not Global. It is restricted a particular application

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@NiloferS 

your email script should be like this

(function runMailScript(current, template, email, email_action, event) {
	
	email.addAddress('cc',current.recipient.email.toString(),current.recipient.name.toString());

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Anand Kumar P
Tera Patron

Hi @NiloferS ,
If you have single recipient you can try script suggested by Ankur if you have multiple recipients try below script in email script

 

if(!current.recipient.nil()){
   var watcherIds = current.recipient.split(",");
   var user =new GlideRecord("sys_user");
   user.addQuery("sys_id", watcherIds);
   user.addQuery("email","!=","");
   user.query();
   while(user.next()){
      email.addAddress("cc", user.email, user.getDisplayValue());
}
}

 

  In Notification: ${mail_script:your_mailscript_name}

 

Thanks,

Anand

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@NiloferS 

your email script should be like this

(function runMailScript(current, template, email, email_action, event) {
	
	email.addAddress('cc',current.recipient.email.toString(),current.recipient.name.toString());

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

I want to send a notification using a workflow. In the "To" field, I have added a distribution list (DL). In the "CC" field, I need to include the "Requested For" user, which will be selected by the user when submitting the form. Could you please suggest how this can be achieved? Do I need to write an email script and reference it in the "To" field as well?

Thanks in advance!

@sameekshasa 

please post a separate question for this, share all the details and tag me there

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

Anand Kumar P
Tera Patron

Hi @NiloferS ,
If you have single recipient you can try script suggested by Ankur if you have multiple recipients try below script in email script

 

if(!current.recipient.nil()){
   var watcherIds = current.recipient.split(",");
   var user =new GlideRecord("sys_user");
   user.addQuery("sys_id", watcherIds);
   user.addQuery("email","!=","");
   user.query();
   while(user.next()){
      email.addAddress("cc", user.email, user.getDisplayValue());
}
}

 

  In Notification: ${mail_script:your_mailscript_name}

 

Thanks,

Anand