- 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 10:31 PM
Hello @subashds6515
In the "Email Body" section, you can use a script to display the incident's previous state and updated state. You can use a script similar to the following:
Incident state has changed from: ${gs.getMessage(previous.state)} to: ${gs.getMessage(current.state)}
Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Thanks & Regards,
Kartik Magadum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 10:48 PM
You may use an event to trigger the notification and pass on the previous state using the event parameters.
Previous: ${parm2}
Current: ${current.state}
- 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-06-2023 12:27 AM
Hi ,
Vishal explanation is correct , follow his process.
Que: Why we need to use the Business rule?
Explanation: previous attribute is available only in Business rules and no where else. In case you need this feature, you will need to create a new field on your form which will store the previous value. You can then use the below code to access the field.