- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2019 12:47 PM
Hey,
I'm creating a catalog item which creates a Task and I'm looking to have the Watch List populated from a group. I've read that the OOB field can't do groups unless I modified the reference field which I don't want to do.
Could I have a glide record look up the group name and have each member added into the Watch List?
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2019 01:54 PM
var gr = new GlideRecord('sys_user_grmember');
var nameString = '';
gr.addQuery('group','~sysid of the group~');
gr.query();
while(gr.next())
{
nameString += gr.user + ',';
}
nameString = nameString.substring(0, nameString.length-1);
current.watch_list = nameString;
I think I got it working with help from your comment. Thank you. Above is my full code if someone needs it later
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2019 12:53 PM
I think you should try the below option suggested:
You can create a reference field with attribute watch_list and set reference table to sys_user_group, reference qualifier simple , active =true.
For more information refer the below link
https://community.servicenow.com/community?id=community_question&sys_id=7be643e5db1cdbc01dcaf3231f961955
Mark my ANSWER as CORRECT and HELPFUL if it helped

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2019 12:55 PM
The watch list is a comma separated list of user sys_ids, and you can get that from a group by querying the sys_user_grmember table for group = sys_id of your group. You can iterate through the members and that the sys_ids to a string of comma separated sys_ids and assign that string to the watch list field. I would do this either through the catalog task workflow activity script section or a business rule on sc_task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2019 01:54 PM
var gr = new GlideRecord('sys_user_grmember');
var nameString = '';
gr.addQuery('group','~sysid of the group~');
gr.query();
while(gr.next())
{
nameString += gr.user + ',';
}
nameString = nameString.substring(0, nameString.length-1);
current.watch_list = nameString;
I think I got it working with help from your comment. Thank you. Above is my full code if someone needs it later
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 08:42 PM
Your code is working.Thhaks
I extended your code to below condition
Condition - if you want to add user first + groups to be populated ( where group is not overriding the current watch list)
var gr = new GlideRecord('sys_user_grmember');
var nameString = '';
gr.addQuery('group','~sysid of the group~');
gr.query();
while(gr.next())
{
nameString += gr.user + ',';
}
nameString = nameString.substring(0, nameString.length-1);
if (current.work_notes_list) {
current.work_notes_list = current.work_notes_list + ',' + nameString;
} else {
current.work_notes_list = nameString;
}