- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Why is template.print() required for the notification to send? Shouldn’t email.setSubject() and email.setBody() be enough to trigger it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
In ServiceNow mail scripts, there are two distinct pieces at play:
-
email object methods (setSubject(), setBody(), addAddress(), etc.)
-
These modify the email metadata (subject, recipients, body text).
-
However, this by itself does not produce any output unless the notification engine has something to render into the email body.
-
-
template.print()
-
This is what actually writes content into the email body when the mail script is executed.
-
Without at least one template.print(), the script doesn’t produce any output stream for the notification engine.
-
Result: ServiceNow thinks the email body is empty -> no email is generated/sent.
-
That’s why when you added even a dummy template.print('Hello …'), the notification suddenly worked - because now there was tangible body content.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ď”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ď”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Shouldn’t email.setSubject() / email.setBody() be enough?
Intuitively, yes — but ServiceNow’s notification engine treats the mail script slightly differently:
-
email.setSubject() → changes the subject, but doesn’t mark the notification as having “content”.
-
email.setBody() → sets body text, but still requires some rendered output (like from template.print()) to make the notification engine commit the message.
-
template.print() → signals “this script has produced output”, which triggers ServiceNow to build and send the email.
Best practice
If you’re writing a pure mail script (not mixing with notification templates):
-
Always include at least one template.print() — even if all you want is to manipulate email object.
-
If you don’t want visible output, you can do:
This ensures the notification is triggered while keeping the body fully controlled via email.setBody().
So in short:
template.print() is the mechanism that tells ServiceNow “I’ve generated output”. Without it, the notification pipeline considers the message empty and skips sending.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ď”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ď”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
If you are using email.setBody() to pass the email body, you need not use template.print() and sending email should work. If you do not have email body, it would expect TemplatePrinter API to set the email body
You can refer below threads for more information
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
In ServiceNow mail scripts, there are two distinct pieces at play:
-
email object methods (setSubject(), setBody(), addAddress(), etc.)
-
These modify the email metadata (subject, recipients, body text).
-
However, this by itself does not produce any output unless the notification engine has something to render into the email body.
-
-
template.print()
-
This is what actually writes content into the email body when the mail script is executed.
-
Without at least one template.print(), the script doesn’t produce any output stream for the notification engine.
-
Result: ServiceNow thinks the email body is empty -> no email is generated/sent.
-
That’s why when you added even a dummy template.print('Hello …'), the notification suddenly worked - because now there was tangible body content.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ď”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ď”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Shouldn’t email.setSubject() / email.setBody() be enough?
Intuitively, yes — but ServiceNow’s notification engine treats the mail script slightly differently:
-
email.setSubject() → changes the subject, but doesn’t mark the notification as having “content”.
-
email.setBody() → sets body text, but still requires some rendered output (like from template.print()) to make the notification engine commit the message.
-
template.print() → signals “this script has produced output”, which triggers ServiceNow to build and send the email.
Best practice
If you’re writing a pure mail script (not mixing with notification templates):
-
Always include at least one template.print() — even if all you want is to manipulate email object.
-
If you don’t want visible output, you can do:
This ensures the notification is triggered while keeping the body fully controlled via email.setBody().
So in short:
template.print() is the mechanism that tells ServiceNow “I’ve generated output”. Without it, the notification pipeline considers the message empty and skips sending.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ď”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ď”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
If you are using email.setBody() to pass the email body, you need not use template.print() and sending email should work. If you do not have email body, it would expect TemplatePrinter API to set the email body
You can refer below threads for more information
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan