Add a group into Watch Lists

RRolling
Tera Guru

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   

1 ACCEPTED SOLUTION

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

View solution in original post

4 REPLIES 4

Ct111
Tera Sage

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

Brad Tilton
ServiceNow Employee
ServiceNow Employee

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.

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

Aruna3
Kilo Contributor

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;
}