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.

mail script for cc not working

samadam
Kilo Sage

I have a mail script to add cc to a notification. The script is getting called as I can see it in the logs and right values. When emails are generated I cannot see that in CC column. How can I fix this? This is a scoped application and both notification and mail script are in the same scope.

2 REPLIES 2

Anupam1
Mega Guru

Hi @samadam ,

 

If your script is executing and logging the correct CC values, but the CC field in the actual email remains empty, here are the key areas to check and fix:

 

Checklist to Fix Missing CC in Notification Emails

  1. Use template.print() Instead of email.addAddress()

In scoped applications, the correct way to add CC recipients in a mail script is:

template.print("cc:email@example.com");

 email.addAddress("cc", "email@example.com") works in global scope but does not populate the CC field in scoped apps.

 

2.   Ensure Notification Is Using the Mail Script

  • Open the Notification record.
  • Under "What will it contain?", confirm your mail script is selected in the "Email script" section.
  • Make sure the script is not just logging but actually printing the CC line.

 

3.  Check Script Output Format

If you're dynamically generating CCs, make sure the output is formatted like this:

template.print("cc:user1@example.com,user2@example.com");

No spaces between emails, comma-separated.

 

4. Verify Notification Conditions

  • Ensure the notification is triggering correctly and not being overridden by other rules.
  • Confirm that the email is sent via the notification, not via a separate email.send() call.

 

5.  Test with a Simple Static Script

To isolate the issue, try a basic mail script:

template.print("cc:test@example.com");

Then trigger the notification and inspect the Email record (sys_email) to see if the CC field is populated.

 

6. Scoped App Permissions

  • Confirm that your scoped app has access to the template object.
  • If you're using a custom script include or utility, make sure it's accessible from the notification context.

 

Debug Tip:-

 

You can add a debug line to your script to confirm execution:

gs.log("Mail script executed with CC: test@example.com", "MyApp");

Then check the System Logs to verify.

 

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

 

Best,

Anupam.

 

lauri457
Giga Sage

What have you tried? I suggest posting your script here. If you are passing a variable as argument to the addAddress method, make sure your variable has the type and value you expect. Other than that it is quite straightforward to add cc from a mail script:

email.addAddress('cc', 'joe.employee@something.com');

And by CC column do you mean the copied column in [sys_email]?