Need help with Business Rule to insert members to watchlist on Incident

babarat1
Tera Contributor

The requirement is as follows:

1. When a new Incident is created with a specific CI or if an Incident is updated with a specific CI as shown below

babarat1_0-1701259596780.png

 

2. It should update the watchlist of that Incident with the members who belong to a related list 

babarat1_1-1701259709838.png

Related list - Watchlist table : u_watchlist

@

Need help with same

TIA

@Ankur Bawiskar @Danish Bhairag2 @Tai Vu @Sandeep Rajput @Dr Atul G- LNG 

5 REPLIES 5

Rahul Talreja
Mega Sage
Mega Sage

Hi @babarat1 ,
Can you try this:

(function executeRule(current, previous /*null when async*/) {
    // Query the u_watchlist table for members related to the specific CI
    var watchList = new GlideRecord('u_watchlist');
    watchList.addQuery('u_ci', current.cmdb_ci);
    watchList.query();
  
    // Loop through the members and add them to the Incident watchlist
    while (watchList.next()) {
        current.watch_list += watchList.u_member + ',';
    }
  
    // Update the Incident record
    current.update();
})(current, previous);

 

Remember to replace 'u_ci' and 'u_member' with the actual field names in your 'u_watchlist' table.

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul