GlideEmailOutbound()-Send Notifications using Script with email template
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
GlideEmailOutbound()-Send Notifications using Script with email template using business rule how we can configure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
Hey @Supriya Mane
One important point to understand is that GlideEmailOutbound and the Notification framework are two different mechanisms in ServiceNow.
Many developers try to use GlideEmailOutbound() with an existing Email Template, but this is generally not the recommended approach because GlideEmailOutbound is designed to build and send an email programmatically, while Email Templates are intended to be rendered through the Notification engine.
Approach
If your requirement is:
Execute a Business Rule - Send an email using an existing Email Template
This approach provides several advantages:
- Separation of business logic and email content
- Reusable email templates
- Easier maintenance
- Supports localization
- Honors user notification preferences
- Email Preview functionality
- Better upgrade compatibility
Step 1 – Create an Email Template
Navigate to:
System Notification → Email → Email Templates
Example:
Template Name
Incident Created Template
Body
Hello ${caller_id.first_name},
Your incident has been created successfully.
Incident Number:
${number}
Short Description:
${short_description}
Priority:
${priority}
Thank you.
Step 2 – Create an Event
Navigate to:
System Policy → Events → Registry
Example
Name:
incident.created.mail
Table:
Incident
Step 3 – Create a Notification
Navigate to:
System Notification → Email → Notifications
Configure:
Table:
Incident
When to Send:
Event is fired
Event Name:
incident.created.mail
Recipients can be:
- Caller
- Assigned To
- Watch List
- Groups
- Users
- Event Parm1 / Parm2
Use your Email Template in the notification body or reference it according to your implementation pattern.
Step 4 – Fire the Event from the Business Rule
Business Rule
(function executeRule(current, previous) { gs.eventQueue( "incident.created.mail", current, current.caller_id, "" ); })(current, previous);
Once the Business Rule executes, ServiceNow automatically:
- queues the event
- processes the notification
- renders the email template
- sends the email
No email formatting is required in your script.
Using GlideEmailOutbound
If you decide to use GlideEmailOutbound, you must construct the email yourself.
Example:
(function executeRule(current, previous) { var email = new GlideEmailOutbound(); email.setSubject("Incident " + current.number); email.setFrom("servicenow@company.com"); email.addAddress("to", current.caller_id.email); email.setBody( "Hello " + current.caller_id.getDisplayValue() + "\n\nIncident Number : " + current.number + "\nShort Description : " + current.short_description ); email.save(); })(current, previous);
This works well for simple scenarios, but everything (subject, body, formatting, recipients, etc.) must be handled in code.
Can GlideEmailOutbound Use an Email Template?
This is one of the most common questions.
The answer is:
Not directly.
There is no supported API such as:
email.useTemplate("Incident Template");
or
email.setTemplate(...)
that allows GlideEmailOutbound to automatically render an Email Template.
Some developers attempt to retrieve records from the sys_email_template table and manually render them using internal or undocumented APIs. While this may work in certain releases, it is not officially recommended, can change between versions, and may introduce upgrade risks.
When Should GlideEmailOutbound Be Used?
GlideEmailOutbound is appropriate when you need to:
- Send fully custom emails from server-side scripts
- Generate dynamic content that doesn't fit the Notification framework
- Send emails from Background Scripts or Script Includes
- Build emails for custom integrations
- Send emails where no Notification record is required
When Should Notifications Be Used?
Notifications are the better choice when you need:
- Reusable email templates
- Event-driven emails
- Multiple recipient types
- HTML formatting
- Localization
- Email Preview
- Notification logs
- User notification preferences
- Easier maintenance by administrators
Final Recommendation
For production implementations, I recommend using Business Rule → Event → Notification Email Template instead of calling GlideEmailOutbound directly.
This keeps business logic separate from presentation, makes email content reusable, allows administrators to modify templates without changing scripts, and fully leverages ServiceNow's notification framework.
Reserve GlideEmailOutbound for scenarios where you need to generate and send a completely custom email in code and do not require Notification features or Email Templates.
***********************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
Hi @Supriya Mane,
GlideEmailOutbound class implements the email object for scoped applications. It is identical to the email global object available in mail scripts. One can use the GlideEmailOutbound class to send an email without creating a notification record in the Instance. Some of the useful methods of GlideEmailOutbound class are mentioned below.
setReplyTo(String address)
This method sets the reply-to address for the email notification. The input type is of string.
setFrom(string address)
This method sets the from address for the email notification. The input type is a string.
addAddress(Sring type,String address)
This method adds the address to either the cc or bcc list of the email. The input type is a string.
setBody(String body Text)
This method adds the body of the email. The input type is a string.
setSubject(String subject)
This method sets the subject of the email. The input type is a string.
save
This method triggers the notification.
Example:
var mail = new GlideEmailOutbound();
mail.setReplyTo('agent@abc.com');
mail.setSubject('Testing outbound email');
mail.addAddress('cc', 'admin@example.com');
mail.setBody('Hello world!');
mail.save();
However, GlideEmailOutbound() class lacks the ability to send attachments or add templates to the outbound email. Because of this ServiceNow recommends sending notifications by events and altering the properties of the email using mail scripts.
Please refer to ServiceNow Docs for more details.
Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Regards,
Ehab Pilloor