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

Vismit Ambre
Giga Guru

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.

VismitAmbre_0-1693982161092.png

 

Let me know if this works for you.

 

Please mark the solution accepted or helpful based on the resolution.

 

Regards,

Vismit