<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Takefumi Muto</title>
    <description>The latest articles on DEV Community by Takefumi Muto (@jackbook).</description>
    <link>https://dev.to/jackbook</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2639070%2F717fd9ef-8e08-4dfc-9507-6f4894b9784c.png</url>
      <title>DEV Community: Takefumi Muto</title>
      <link>https://dev.to/jackbook</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jackbook"/>
    <language>en</language>
    <item>
      <title>Implementing Event-Triggered Notifications in ServiceNow</title>
      <dc:creator>Takefumi Muto</dc:creator>
      <pubDate>Sun, 14 Sep 2025 21:16:54 +0000</pubDate>
      <link>https://dev.to/jackbook/implementing-event-triggered-notifications-in-servicenow-1kik</link>
      <guid>https://dev.to/jackbook/implementing-event-triggered-notifications-in-servicenow-1kik</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In ServiceNow, the most common way to send a Notification is to trigger it when a record is inserted or updated.&lt;br&gt;
However, sometimes this approach is not flexible enough, especially when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The condition is too complex for the GUI.&lt;/li&gt;
&lt;li&gt;You need to compare &lt;strong&gt;old and new values&lt;/strong&gt; in the notification.&lt;/li&gt;
&lt;li&gt;You want to &lt;strong&gt;suppress notifications for API calls&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You want to &lt;strong&gt;reuse the same trigger across multiple notifications or processes&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where &lt;strong&gt;event-triggered notifications&lt;/strong&gt; come in handy.&lt;br&gt;
In this post, I’ll walk you through an implementation where a notification is sent when the &lt;strong&gt;priority of an Incident changes&lt;/strong&gt;, using an Event as the trigger.&lt;/p&gt;


&lt;h2&gt;
  
  
  Implementation Steps
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Event Registry
&lt;/h3&gt;

&lt;p&gt;First, create a custom Event Registry entry.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name&lt;/strong&gt;: &lt;code&gt;Test_incident.priority_changed&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Table&lt;/strong&gt;: &lt;code&gt;incident&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Event fired when the priority changes
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;event_name&amp;gt;&lt;/span&gt;Test_incident.priority_changed&lt;span class="nt"&gt;&amp;lt;/event_name&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;incident&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;Event Registration of test&lt;span class="nt"&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Business Rule: Fire the Event
&lt;/h3&gt;

&lt;p&gt;Next, create a Business Rule that fires the event whenever the priority changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name&lt;/strong&gt;: &lt;code&gt;Test_incident events&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Table&lt;/strong&gt;: &lt;code&gt;incident&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When&lt;/strong&gt;: after update
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;previous&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;gs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eventQueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Test_incident.priority_changed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// event name&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                           &lt;span class="c1"&gt;// source record&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;       &lt;span class="c1"&gt;// parm1: new priority&lt;/span&gt;
        &lt;span class="nx"&gt;previous&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;       &lt;span class="c1"&gt;// parm2: old priority&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Optional: exclude updates from Connect API&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isConnect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;transaction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GlideTransaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRequestURI&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;api&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;now&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;connect/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;👉 Here, I’m passing &lt;strong&gt;parm1&lt;/strong&gt; (new priority) and &lt;strong&gt;parm2&lt;/strong&gt; (old priority) so they can be referenced later in the notification body.&lt;/p&gt;


&lt;h3&gt;
  
  
  3. Notification
&lt;/h3&gt;

&lt;p&gt;Now, configure the Notification that listens for the event.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name&lt;/strong&gt;: &lt;code&gt;Test_Event trigger notification&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When to send&lt;/strong&gt;: Event is fired → &lt;code&gt;Test_incident.priority_changed&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subject&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Test Subject: ${number}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Body&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Incident ${number} priority has changed!
  Previous: ${event.parm2}
  Current:  ${event.parm1}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Unit Test
&lt;/h3&gt;

&lt;p&gt;Finally, let’s test with an Incident record.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Incident&lt;/strong&gt;: &lt;code&gt;INC0010005&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Short description: Event Trigger Notification Test&lt;/li&gt;
&lt;li&gt;Priority: changed from 3 → 1&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Notification Result&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Subject:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Test Subject: INC0010005
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Incident INC0010005 priority has changed!
Previous: 3
Current:  1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Works as expected — the event parameters were passed into the notification successfully.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use Events?
&lt;/h2&gt;

&lt;p&gt;From this small experiment, I can summarize the main benefits of event-triggered notifications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle &lt;strong&gt;complex conditions&lt;/strong&gt; via scripts.&lt;/li&gt;
&lt;li&gt;Easily &lt;strong&gt;insert old/new values&lt;/strong&gt; into notifications.&lt;/li&gt;
&lt;li&gt;Reuse the same event across &lt;strong&gt;multiple notifications or flows&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prevent unnecessary notifications&lt;/strong&gt; (e.g., API updates).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For simple cases like “notify the assignee when an Incident is created,” a standard notification is fine.&lt;br&gt;
But once conditions get more advanced, &lt;strong&gt;events give you much more control&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Here’s the overall flow again:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Register the event in &lt;strong&gt;Event Registry&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Use a &lt;strong&gt;Business Rule&lt;/strong&gt; to fire the event with &lt;code&gt;gs.eventQueue()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a &lt;strong&gt;Notification&lt;/strong&gt; triggered by the event.&lt;/li&gt;
&lt;li&gt;Pass parameters (&lt;code&gt;parm1&lt;/code&gt;, &lt;code&gt;parm2&lt;/code&gt;) for richer notification content.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach is flexible, reusable, and prevents unwanted notifications.&lt;/p&gt;




&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use Flow Designer to trigger Slack messages from the event.&lt;/li&gt;
&lt;li&gt;Explore &lt;strong&gt;Notification Email Scripts&lt;/strong&gt; for richer email content.&lt;/li&gt;
&lt;li&gt;Try applying the same pattern to Change or Problem records.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;✍️ That’s it! This was a simple but effective pattern for &lt;strong&gt;event-triggered notifications in ServiceNow&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>basic</category>
      <category>servicenow</category>
    </item>
  </channel>
</rss>
