- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 10:11 AM
I have written a email script with below code.
This is not working as expected. What could possibly went wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 11:43 AM
Hi NiloferS,
I can suggest a few things:
- The documentation shows email.addAddress() with three arguments. The third one seems to be optional, but you never know.
- Are you sure that you have the mail script name exactly the same as it exists for that object. Remember this is the Linux world so case matters.
- Have you tried embedding diagnostics (gs.log) in the script to see if it is getting called or if there is some other error? Along with that, when you test, have you checked for errors or warnings?
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 01:04 PM
Hi @NiloferS,
I am assuming the notification table is configured on the [u_table].
Within the script, replace the first line of code with var cRecord = current;
Also, addAddress takes 3 parameters which might be all mandatory.
Cheers
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 04:43 PM
Hi @NiloferS ,
Can you please try the below code-
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var cRecord = current;
var ccEmail = cRecord.getValue('on_behalf_email');
if (ccEmail) {
email.addAddress('cc', ccEmail);
}
})(current, template, email, email_action, event);
Take a look into the below documentation as well.
https://docs.servicenow.com/bundle/vancouver-platform-administration/page/script/server-scripting/re...
As James suggested you can take a look into the below script along with the explanation on Docs site-
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:11 PM
Hi there,
Regarding "This is not working as expected. What could possibly went wrong?"
How are you testing this? By previewing messages? Are actually sending out emails and verifying those? Good to know, CC / BCC doesn't work "correctly" when previewing, though does work when actually sending emails.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 11:43 AM
Hi NiloferS,
I can suggest a few things:
- The documentation shows email.addAddress() with three arguments. The third one seems to be optional, but you never know.
- Are you sure that you have the mail script name exactly the same as it exists for that object. Remember this is the Linux world so case matters.
- Have you tried embedding diagnostics (gs.log) in the script to see if it is getting called or if there is some other error? Along with that, when you test, have you checked for errors or warnings?
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 01:04 PM
Hi @NiloferS,
I am assuming the notification table is configured on the [u_table].
Within the script, replace the first line of code with var cRecord = current;
Also, addAddress takes 3 parameters which might be all mandatory.
Cheers
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 04:43 PM
Hi @NiloferS ,
Can you please try the below code-
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var cRecord = current;
var ccEmail = cRecord.getValue('on_behalf_email');
if (ccEmail) {
email.addAddress('cc', ccEmail);
}
})(current, template, email, email_action, event);
Take a look into the below documentation as well.
https://docs.servicenow.com/bundle/vancouver-platform-administration/page/script/server-scripting/re...
As James suggested you can take a look into the below script along with the explanation on Docs site-
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 08:11 PM
Hi there,
Regarding "This is not working as expected. What could possibly went wrong?"
How are you testing this? By previewing messages? Are actually sending out emails and verifying those? Good to know, CC / BCC doesn't work "correctly" when previewing, though does work when actually sending emails.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field