how to add dynamically cc to email notification

kandunurimahesh
Tera Contributor
 
4 REPLIES 4

Manmohan K
Tera Sage

Hi @kandunurimahesh ,

 

To dynamically add cc, create an email script and use below code in that script (Add condition appropriately)

 

 

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

var user = new GlideRecord("sys_user");
user.addQuery("sys_id", current.caller_id); // Apply your filter to get user
user.query();
while(user.next()){

email.addAddress("bcc",user.getValue('email_address'),user.getValue('name'));

email.addAddress("cc",user.getValue('email_address'),user.getValue('name'))
}


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

 

 

 

Now you can call the above mail script in email notification body as ${mail_script:script name}

Here replace script name with the exact name of the notification email script you have created initially

Eeshamayee kon1
Tera Expert

Hello @kandunurimahesh ,

 

You can create email script and use below API to add cc in a notification.

email.addAddress("cc", emailaddress, addressname);

 

Please verify below email script for reference:

Email Script:

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

    email.addAddress("cc", current.u_manager.email.toString(), current.u_manager.name.toString());

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

 

If my answer helped you in any way, please then mark it as helpful.

Thank you.

 

kandunurimahesh
Tera Contributor

When ever an event is triggered via notification the notification is going to the given user ..But I want to add the manager in the cc dynamic

kandunurimahesh
Tera Contributor

first we have to creat event registry

next event regisrty we hav to call in business rule(

gs.eventQueue('set.manager',current,'kandunurimahesh1@gmail.com',current.caller_id.manager.email);

)

next we have to create notification 

next we will creat mail script and we will add in notification in html body ${mail_script:script name} 

is this correct way to create 

can u provide clear steps