Add User in CC of an email

may13
Tera Contributor
Hello,
I have a requirement in my current project where I need to create an email script in ServiceNow. In the User table, I have three custom fields: L1 Approval, L2 Approval, and HR Employee. I need to include the users from these fields in the CC section of a notification. Could you please provide the email script?

 

6 REPLIES 6

RaghavSh
Mega Patron

what is the table of your notification. L1, L2 and FR will be based on some user for example requested for.

 

var ccEmails = current.requested_for.L1_approval +"," + current.requested_for.L2_approval + ","+ current.requested_for.hr_employee.

 

email.addAddress('cc' ,ccEmails) ;
 
You need to update the fieldnames/variables as per your need. requested_for, L1_approval etc have to be your field names.
 

Raghav
MVP 2023
LinkedIn

may13
Tera Contributor

@RaghavSh     

The table is HR Profile, and this notification will be received by the user.
and in CC we need to add L1 ,L2 and HR 

nayanmule
Kilo Sage

@may13  , This is very simple.

Create a new mail script with any name.

 

Add a script in the mail script 

email.addAddress("cc", current.requester.manager.email, current.requester.manager.name);

 Replace current.requester.manager.email with your fields name like - current.approval1, current.approval2.

 

Call the Script in Your Notification:

  • Go to the notification (e.g., Incident [sys_notification]) you want to modify.
  • In the What it will contain tab, find the Message HTML (or Plain Text) field.
  • Add your email script as ${mail_script:your_email_script_name}  

 

Follow this for more information - How to add CC in an email notification  

https://www.servicenow.com/community/developer-articles/send-an-email-to-any-person-as-cc-bcc/ta-p/2...

 

If my response has helped you, kindly mark it as helpful and accept the solution.

Regards,

Nayan

yashkamde
Giga Guru

Hello @may13 , 

 

Use this script according to your requirement,

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

	 email.addAddress('cc', L1_approval.email, 'L1_approval.name');
         email.addAddress('cc',  L2_approval.email, 'L2_approval.'name);
         email.addAddress('cc', hr_employee.email, 'hr_employee.name');

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

 
If my response helped mark as helpful and accept the solution..