Need help adding manager to a watchlist using business rules

JMitchell
Kilo Expert

Hello everybody,

I'm working on a business rule script to add a user's manager to a watchlist. I have a script that is working, and it validates the manager isn't already a member of the watchlist. What I'm looking for here, is maybe an idea on how I would dynamically change the manager if the caller changes. Also, if you have an idea on how I can do this better, I'm always open to suggestions. 

(function executeRule(current, previous /*null when async*/) {
// Add your code here

var wl = current.watch_list.toString();
var array = wl.split(",");
var mgr = current.caller_id.manager;

if (current.watch_list == ''){
current.watch_list += mgr;
} else if (array.indexOf(mgr) > -1 && current.watch_list != ''){
current.watch_list += ',' + mgr;
}

})(current, previous);

 

Thank you in advance,

James Mitchell

1 ACCEPTED SOLUTION

This will help

https://community.servicenow.com/community?id=community_blog&sys_id=a84daee5dbd0dbc01dcaf3231f96198e

View solution in original post

7 REPLIES 7

Mike Patel
Tera Sage

try

var wl = current.watch_list;
var mgr = current.caller_id.manager.sys_id;

if (wl != ''){
wl = (wl + ',' + mgr);
}else{
current.watch_list = mgr;
}

I tried that originally. I have the script running on Insert and Update. I have to keep the Update box checked because there are times in our enivornment where people will open a ticket for somebody else and they have different managers. So we change the caller. When Update is on, it keeps adding the manager with each change.

Looks like your script will work. So you want to remove caller manager and add new manager as watcher ?

If it's possible to do it with a script when the caller name changes, yes. Otherwise, our Service Desk team will do it manually. I would just like to minimize human error, where possible.