- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 12:45 PM
We have a request that when an incident is created and needs to be escalated to another assignment group, that the opened by user is not part of, to add the opened by user to the watch list.
It is partially working, but it always adds the opened by user to the watch list regardless if they are part of the group selected or not.
We created a business rule to Add Opened by user to watch list
- When to run
- Before
- Insert/update
- Advanced
- Condition
- current.assignment_group.changes() && !current.assignment_group.getMembers().contains(current.opened_by)
- Script
(function executeRule(current, previous /*null when async*/) {
// Check if assignment group has changed
if (current.assignment_group.changes()) {
var assignmentGroup = current.assignment_group.getRefRecord();
var openedByUser = current.opened_by.getRefRecord();// Check if the opened by user is not a member of the new assignment group
if (assignmentGroup && openedByUser && !assignmentGroup.getMembers().contains(openedByUser)) {
// Add the opened by user to the watch list
current.watch_list = current.watch_list + ',' + current.opened_by;
}
}
})(current, previous);
- Condition
What are we missing?
Thank you!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 01:41 PM
Hi @mfoster817 You can try to use below script in business rule, that will solve your requirement.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if ((current.watch_list.indexOf(current.opened_by)== -1 || current.watch_list.isNil()) && !gs.getUser().getUserByID(current.opened_by).isMemberOf(current.assignment_group))
current.watch_list += ","+current.opened_by;
})(current, previous);
Note: Just set only one filter condition on your business rule < Assignment Group > <Changes>
Hope it will help you.
Thanks,
Harsh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 01:02 PM
I dont think you can use this !current.assignment_group.getMembers().contains(current.opened_by)
Instead you can query the User Group table and get the assignment.
-
(function executeRule(current, previous /*null when async*/) {
// Check if assignment group has changed
if (current.assignment_group.changes()) {
var assignmentGroup = new GlideRecord('sys_user_group');
assignmentGroup.addQuery('group',current.assignment_group);assignmentGroup.addQuery('user',current.opened_by);
assignmentGroup.query();
// Check if the opened by user is not a member of the new assignment group
if (assignmentGroup.next()) {
// Add the opened by user to the watch list
current.watch_list = current.watch_list + ',' + current.opened_by;
}
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 01:41 PM
Hi @mfoster817 You can try to use below script in business rule, that will solve your requirement.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if ((current.watch_list.indexOf(current.opened_by)== -1 || current.watch_list.isNil()) && !gs.getUser().getUserByID(current.opened_by).isMemberOf(current.assignment_group))
current.watch_list += ","+current.opened_by;
})(current, previous);
Note: Just set only one filter condition on your business rule < Assignment Group > <Changes>
Hope it will help you.
Thanks,
Harsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 11:27 PM
Hi @mfoster817
- Instead of concatenating the current.opened_by value to the current.watch_list using the + operator, the push() method is used to add the current.opened_by value to the current.watch_list array.
(function executeRule(current, previous /*null when async*/) {
// Check if assignment group has changed
if (current.assignment_group.changes()) {
var assignmentGroup = current.assignment_group.getRefRecord();
var openedByUser = current.opened_by.getRefRecord();
// Check if the opened by user is not a member of the new assignment group
if (assignmentGroup && openedByUser && !assignmentGroup.getMembers().contains(openedByUser)) {
// Add the opened by user to the watch list
current.watch_list.push(current.opened_by);
}
}
})(current, previous);
Please Mark this Helpful and Accepted. If this solves your query
Regards,
Deepak Sharma