- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 10:20 PM
Hi,
Create email notification on the incident table.
Subject: Incident state Changed.
Body: incident previous state and updated state.
How to display the incident's previous state and updated state in the email body?
Thanks,
Subash
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 10:49 PM
Hello Subash,
Step 1. Create event registry
e.g, incident.state.change
Step 2. In notification "When to send" section
Step 3. You can write onBefore/onAfter Business rule as per your requirement to trigger the notification.
When to Run : State changes
Script :
(function executeRule(current, previous /*null when async*/) {
var previousState = previous.getDisplayValue('state');
var currentState = current.getDisplayValue('state');
//pass both the values in event parameter
gs.eventQueue('incident.state.change',current,currentState,previousState);
})(current, previous);
In the Notification :
incident previous state = ${event.parm2}
updated state = ${event.parm1}
Output :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 11:36 PM
Hi Subash,
This will have to leverage below components to get working:
1) Create an event - "incident.state_changed" on the "incident" table
2) Create a Business Rule "Incident State Changed" & pass the previous and current state
(function executeRule(current, previous /*null when async*/ ) {
gs.eventQueue('incident.state_changed', current, previous.state.getDisplayValue(), current.state.getDisplayValue());
})(current, previous);
3) Create a notification that will be consuming the event you created in step 1
4) Create a notification email script and call this in your notification email body
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var emailBody = '<p>Incident State Was - ' + event.parm1 + '.<br/>Incident State Is - ' + event.parm2 + '.</p>';
template.print(emailBody);
})(current, template, email, email_action, event);
And you should be done.
Let me know if this works for you.
Please mark the solution accepted or helpful based on the resolution.
Regards,
Vismit