- 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
‎08-30-2016 07:54 PM
Can your ESS user 'read' Location and Department fields on the sys_user table? Try logging out: gs.log("User location: "+ current.caller_id.location); on the first line of your BR and see if you get anything. If not you will have to adjust your sys_user table ACLs in order for your BR to run as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 09:59 PM
Hey Masha,
Thank you very much for your quick response. I placed the gs.log statement you mentioned as well as a gs.addInfoMessage on my script to test. I then opened a new ticket impersonating the ESS user and I received the location sys_id message as well as a syslog entry for User location ("source: *** Script"). Unfortunately the watch_list users were not added to the new incident. I was really hoping you had the right answer for me, been scratching my head over this for a few hours now. Could it possibly be some other permission issue (i.e. public vs private function)?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2016 06:04 AM
Can ESS user write to watch_list?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 11:56 AM
Hey Masha,
Do I check that by going to the System Definition > Tables> incident table and looking at access controls? I see an 2 ACs named incident.watch_list for "write", one for 2 roles (itil and engagement_member) and the other with no restrictions. Sorry if I'm not looking in the correct location.
Is it possible that because there is no "watch_list" on the ESS user's custom incident creation form (record producer?), I can't assign value to that variable until after the incident has been created? When I create an incident as impersonating any user (i.e. not using the ess portal), the watch_list is already present on the creation form before submitting and the script functions as intended.
Best,
Mathew