Add users to Worknotes list

Shiva Kumar8
Kilo Guru

Hi,

I want to add user ABCD to work notes list and E in watchlist for a request if assignment group is X or Y

I'm using the below script

current.watch_list="sysid of E".toString();
current.work_notes_list=="sysidA".toString()+","+"sysidB".toString()+","+"sysidC".toString()+","+"sysidD".toString();

I wab able to add the E to watchlist but ABCD are not adding into the worknotes list I'm I doing anything wrong in the script please help, 

also if assignment group changes from X or Y to some other group the watchlist and worknotes list should clear the values.

please help.

Thanks.

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

current.work_notes_list==  is this a typo?

View solution in original post

5 REPLIES 5

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Shiva,

You can easily achieve this with a before business rule on your chosen task table (on insert/update)

Make sure the filter condition is set to Assignment group changes

This way the watch list & work notes list fields will update with new users every time the group is changed (will overwrite previous values)

Enter this in the script field

(function executeRule(current, previous /*null when async*/) {

	//Get Group members from Assignment Group
	
	member_array = [];
	
	var grp_members = new GlideRecord('sys_user_grmember');
	grp_members.addQuery('group',current.assignment_group);//use the assignment group from the incident
	grp_members.query();
	
	while(grp_members.next()){
	member_array.push(grp_members.user.sys_id.toString());//push the group members user record sys_id to the array	
	}
	
	current.work_notes_list = member_array.toString();
	current.watch_list = current.work_notes_list;

})(current, previous);

Hope this works for you