IT CanvassTalk to an advisor
Development · LessonBy , ServiceNow Trainer, 8 yrs · Published · current release · beginner

Notifications & email scripts

Send the right message to the right people, with dynamic content via mail scripts.

Quick answer

Notifications send email (and push/SMS) when something happens, a P1 incident, an approval request, an SLA breach. They are configured records: a when to send trigger, a who to send to audience, and a what to say body. Email scripts inject dynamic, computed content into that body.

Key takeaways
  • How a notification fires
  • A mail script
  • Best practices
  • Try it Yourself

Send the right message to the right people, with dynamic content via mail scripts.

Notifications send email (and push/SMS) when something happens, a P1 incident, an approval request, an SLA breach. They are configured records: a when to send trigger, a who to send to audience, and a what to say body. Email scripts inject dynamic, computed content into that body.

How a notification fires

  • Trigger, record inserted/updated matching a condition, or an event raised by code.
  • Recipients, users, groups, fields on the record (e.g. Assigned to), or dynamic lists.
  • Content, a template with field variables like ${number} and mail scripts for logic.

A mail script

// In the notification body: ${mail_script:sla_line} (function runMailScript(current, template, email, email_action, event) { if (current.priority == '1') { template.print('\u26a0 This is a P1 and needs immediate attention.'); } })(current, template, email, email_action, event);
Events decouple the trigger. For anything beyond a simple field condition, raise an event (gs.eventQueue()) from a business rule and have the notification listen for it. This keeps notification logic out of your business rules and makes the trigger reusable.

Best practices

  • Use notification email scripts, not inline logic, for anything conditional.
  • Respect subscription preferences and avoid notification storms.
  • Test with the preview and check the email logs.
Practise this on your own free instance.
Set up your free instance →
Try it YourselfJavaScript
▸ Press Run to execute.

Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
An email script is used to...
Practise this on your own free instance.
Set up your free instance →
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support