- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 07:14 PM
Hello all,
I am rather new to ServiceNow development so please excuse my lack of understanding, I am learning as I go. I am having trouble with a business rule I've created for a requirement we have whereby we need to add all users to an incident watchlist that matche the current caller's location and department. I need this to run whenever a new incident or request is created, or if the location/contact field of either is updated. The script works fine when I create or update incidents as my user (admin role), but fails to add anyone to the watch list when an ESS user creates a new INC or REQ. Is a business rule the best way to go about this? I can't figure out a trigger that will execute this when an ESS user creates a ticket. Any help would be much appreciated.
Here's my current business rule script:
Runs: before Insert/Update, when contact or location changes. (also tested "after" with no success)
//This custom business rule runs anytime the 'location' or 'contact' fields on an 'incident' record are updated or inserted.
(function executeIncWatchlistRule(current, previous) {
var watchList = current.watch_list;
var wlUser = new GlideRecord('sys_user');
var calLoc = current.caller_id.location;
var calDep = current.caller_id.department;
//regex of dept sys_ids removed for this post
if (calDep.match(/^(myhiddenregex)$/)) {
wlUser.addQuery('location', calLoc);
wlUser.addQuery('department', calDep);
wlUser.query();
while (wlUser.next()) {
var userToAdd = wlUser.sys_id;
var presence = watchList.search(userToAdd);
if (presence == -1) {
watchList = (watchList + "," + userToAdd);
}
}
current.watch_list = watchList;
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 12:12 PM
Hey Masha,
I tested by mapping a variable in the record producer to the watch_list in order to have that present on incident creation and that solved my issue! I very much appreciate your suggestion here.
Best,
Mat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 12:12 PM
Hey Masha,
I tested by mapping a variable in the record producer to the watch_list in order to have that present on incident creation and that solved my issue! I very much appreciate your suggestion here.
Best,
Mat

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 12:14 PM
I am glad you got it figured out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 12:35 PM
Masha,
Your suggestions got me pointed in the right direction to resolve this. Thanks again