- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 06:56 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 07:50 AM
This will help
https://community.servicenow.com/community?id=community_blog&sys_id=a84daee5dbd0dbc01dcaf3231f96198e

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 07:00 AM
try
var wl = current.watch_list;
var mgr = current.caller_id.manager.sys_id;
if (wl != ''){
wl = (wl + ',' + mgr);
}else{
current.watch_list = mgr;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 07:04 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 07:43 AM
Looks like your script will work. So you want to remove caller manager and add new manager as watcher ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 07:45 AM
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.