Email Notification

subashds6515
Tera Contributor

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

 

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello Subash,

 

Step 1. Create event registry 

e.g,  incident.state.change

 

Step 2. In notification  "When to send" section

 

VishalBirajdar7_3-1693979281108.png

 

Step 3. You can write onBefore/onAfter Business rule as per your requirement to trigger the notification.

 

When to Run : State changes

 

VishalBirajdar7_0-1693978898333.png

 

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}

 

VishalBirajdar7_1-1693979065895.png

 

Output : 

 

VishalBirajdar7_2-1693979146442.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

5 REPLIES 5

Kartik Magadum
Kilo Sage

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

 

Albert
Tera Contributor

You may use an event to trigger the notification and pass on the previous state using the event parameters.

 

Previous: ${parm2}
Current: ${current.state}

Vishal Birajdar
Giga Sage

Hello Subash,

 

Step 1. Create event registry 

e.g,  incident.state.change

 

Step 2. In notification  "When to send" section

 

VishalBirajdar7_3-1693979281108.png

 

Step 3. You can write onBefore/onAfter Business rule as per your requirement to trigger the notification.

 

When to Run : State changes

 

VishalBirajdar7_0-1693978898333.png

 

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}

 

VishalBirajdar7_1-1693979065895.png

 

Output : 

 

VishalBirajdar7_2-1693979146442.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Community Alums
Not applicable

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.