Previous field value not available in Notification on CMDB table (cmdb_ci_business_app)

SunilkumarP1632
Tera Contributor

Hi Team,

 

I am working on a notification requirement for Business Applications (cmdb_ci_business_app) where an email should be sent when the Operational Status changes, including both FROM and TO values.

 

Configuration details:

 

Table: cmdb_ci_business_app

Notification trigger:

Send when: Record Updated

Inserted: Unchecked

Condition: Operational status changes

 

Email content:

Previous Status: ${previous.operational_status}
Current Status: ${operational_status}

 

Observed behavior:

Notification triggers correctly on update

Current status value is populated

Previous status value is blank, even though the field value is clearly changing

 

preview 

SunilkumarP1632_0-1768362447970.png

 

SunilkumarP1632_1-1768362489381.png

 

 

 

Expected behavior (example)

 

If a Business Application has:

Operational Status = Operational

 

And it is updated to:

Operational Status = Non-Operational

 

Then the notification email should contain:

Previous Status: Operational
Current Status: Non-Operational

 

 

 

please help me here how to fix this 

1 ACCEPTED SOLUTION

AnkurB001561062
Tera Patron

@SunilkumarP1632 

you can't use Previous object in notification body directly

Other way

-> after update BR on cmdb_ci_business_app, Condition: Operational status changes

Script:

(function executeRule(current, previous /*null when async*/) {

    var oldStatus = previous.operational_status.getDisplayValue();
    var newStatus = current.operational_status.getDisplayValue();
  
    var param1 = "Previous Status: " + oldStatus + "<br/>" + "Current Status: " + newStatus;

    // Trigger the event, passing the data
    gs.eventQueue('your_event_name', current, param1, current.assigned_to); // Create 'your_event_name' in System Policy > Events

})(current, previous);

-> create event on that table and use that in BR script

-> also create notification on your table and make it trigger on your Event

-> Event parm2 contains recipient - True and this is the recipient to whom email will be sent

AnkurBawiskar_0-1768366376651.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

DrewW
Mega Sage

Previous does not exist in the way you are using it.  You are going to have to use a mail script.  If that does not work out a business rule and using gs.eventQueue or a flow are your next options.

@DrewW  - 

 

could you please help me with flow or business rule .

A google or Bing search on 

"servicenow use gs.eventqueue to trigger a notification"

will get you all the instructions you need to use a business rule to get this done.

 

Dhanraj B
Tera Guru

I think you won't be able to fetch the previous value directly in email body. You can write a business rule in CMDB Business Application table, when the operational status changes fire an event. 

gs.eventQueue("event_name",current,previous.operational_status,null);

 

Then, change the notification trigger to "Event is fired". After that, you have to create an email script something like below.

 

(function runMailScript(current, template, email, email_action, event) {
    template.print(event.parm1);
})(current, template, email, email_action, event);

 

In your email body, call your mail script - ${mail_script:your_mail_script_name}. I believe this will help you to get the previous state.