Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business rule script

Sanjeev Mishra
Giga Contributor

Hi All, Need help to write a BR where we have to add email id (example@gmail.com) when ever any case / incident will create for an specifce CI(configuration Item). Thanks all in advance. Regards, Sanjeev

2 REPLIES 2

Community Alums
Not applicable

Hey there,

 

You should be able to accomplish this using a Business Rule where you conditions are:
Configuration Item <is> <the CI you need>.

In the script, you only need 1 line:
current.watch_list += ",example@gmail.com";

 

~Nick

Sandeep Rajput
Tera Patron
Tera Patron

@Sanjeev Mishra Here is the script for an onBefore business rule which adds a specific email to watchlist if the incident is related to a specific CI.

 

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

    // Check if the record is related to the specific Configuration Item
    var specificCI = 'sys_id_of_specific_ci'; // Replace with the sys_id of your CI
    
    if (current.cmdb_ci == specificCI) {
        // Add 'example@gmail.com' to the watchlist if it's not already present
        var watchlist = current.watch_list.toString();
        
        if (!watchlist.includes('example@gmail.com')) {
            current.watch_list += ',example@gmail.com';
        }
    }

})(current, previous);