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.

Email notification is not triggering to CC

Renu9
Tera Contributor

Hi All,

 

I am having a  requirement to send the notification to contact person and cc to the manager.

I have written an email script "cc_to_manager", 

 

(function runMailScript(current, template, email, email_action, event) {
    email.addAddress("cc", current.manager.email.toString(), current.manager.getDisplayValue());
})(current, template, email, email_action, event);
 
It is not sending the email to CC. 
I also tried below but didnt worked
    email.addAddress("cc", current.contact.manager.email.toString(), current.contact.manager.getDisplayValue());
 
email.addAddress("cc", current.variables.requested_for.manager.email.toString(), current.variables.requested_for.manager.getDisplayValue());
 
Calling in the notification like :${mail_script:cc_to_manager}
 
Please guide me here
7 REPLIES 7

So contact person is then "current.contact"? Correct?

And contact is a reference to sys_user? Correct?

In that case it sounds like current.contact.manager.email could an option.

 

Or is this logic in your situation different?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Yes @Mark Roethof 

That is correct and as per below I was able to get the email address of manager in the logs.

But when email is generated , I am not seeing the manager email address in copied.

Renu9_0-1705414600172.png

(function runMailScript(current, template, email, email_action, event) {
    gs.error("manager is " + current.contact.manager.email);
    email.addAddress("cc", current.contact.manager.email, current.contact.manager.getDisplayValue());
   
})(current, template, email, email_action, event);

Renu9
Tera Contributor

Hi @Mark Roethof 

I tried a different option and it worked well.

    var gr = new GlideRecord('tablename');
    gr.addQuery('sys_id', current.sys_id);
    gr.query();
    if (gr.next()) {
        email.addAddress("cc", gr.contact.manager.email.toString());
    }