How to capture the watch list value in a variable in servicenow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 10:56 AM
Hi All,
How to capture watch list value in a business rule via variable
I did write the code
var watch= current.watch_list;
But the variable "watch" isn't capturing the watch list vale.
How to achieve this?
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 11:43 AM
@phr The condition is failing because the current.sys_updated_by returns a user name (e.g. abel.tuter) whereas the watchlist contains a comma separated list of user sys_ids. I recommend using the following piece of code to fetch sys_id if the user from user name.
var updated = '';
var userName = current.sys_updated_by;
var userRec = GlideRecord('sys_user');
if(userRec.get('user_name',userName)){
updated = userRec.getValue('sys_id');
}
Add the above lines in your code and your watch list contains check will start working.
Hope this helps.