When we add or remove users from incident watchlist, same should also get updated on case form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:03 AM
Hi All,
I have requirement where if we add or remove users from incident Watchlist then same should also reflect in case.
This requirement is only one directional from incident to Case.
E.g. Scenario1:- If we add two users A,B in the incident watchlist then it should also get added in the case watchlist.
Scenario2:- On Case already we have two users in the watchlist A, B, if we add C user in the incident watchlist then C user should also get added into Case watchlist (A,B,C)
Scenario3:-On Case already we have two users in the watchlist A, B, C if we remove C user from the incident watchlist then C user should also get removed into Case watchlist (A,B)
Can you please help me how to implement this requirement.
Thanks in Advance,
Shantanu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:08 AM
Hi @Shantanu_99,
Your scenarios sound like you just want the watchlist the same in incident as in case.
But I have a feeling you also want the scenario:
Case Watchlist A,B,C,D,E
Incident watchlist A,B
Incident Watchlist G is added so becomes A,B,G then Case shoud become A,B,C,D,E,G
Or
Case Watchlist A,B,C,D,E
Incident watchlist A,B
Incident Watchlist A is removed so becomes B then Case shoud become B,C,D,E,G
If that is not the case, you could simply say case.watch_list = incident.watch_list.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:19 AM
Hi Peter,
Case Watchlist A,B,C,D,E
Incident watchlist A,B
Incident Watchlist G is added so becomes A,B,G then Case shoud become A,B,C,D,E,G
Incident Watchlist A is removed so becomes B then Case shoud become B,C,D,E,G
I want like this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:48 AM
Hi @Shantanu_99
Try below script:
function getDifference(array1, array2) {
// Create a new array to store the difference.
var difference = [];
// Iterate over the first array.
for (var i = 0; i < array1.length; i++) {
var element = array1[i];
// Check if the element is not in the second array.
var index = array2.indexOf(element);
if (index === -1) {
// Add the element to the difference array.
difference.push(element);
}
}
// Return the difference array.
return difference;
}
function removeValues(array, valuesToRemove) {
// Create a new array to store the results.
var results = [];
// Iterate over the original array.
for (var i = 0; i < array.length; i++) {
var element = array[i];
// Check if the element is in the values to remove array.
var found = false;
for (var j = 0; j < valuesToRemove.length; j++) {
if (element === valuesToRemove[j]) {
found = true;
break;
}
}
// If the element is not in the values to remove array, add it to the results array.
if (!found) {
results.push(element);
}
}
// Return the results array.
return results;
}
var previousArray = [1, 2, 3, 4, 5]; //previous.watch_list incident
var currentArray = [3, 4, 5, 6, 7]; //current.watch_list incident
var differenceAdded = getDifference(previousArray, currentArray);
var differenceRemoved = getDifference(currentArray, previousArray);
gs.info('Added Users: ' + differenceAdded); // [1, 2]
gs.info('Removed Users: ' + differenceRemoved); // [6, 7]
var caseArray = [3, 4, 5, 6, 7, 8]; //current.watch_list case
var caseArrayRemovedValues = removeValues(caseArray, differenceRemoved);
gs.info('New Case Watchlist without removed values: ' + caseArrayRemovedValues); // [1,2,3,4,5,8]
var caseArrayAddedValues = caseArrayRemovedValues.concat(differenceAdded);
gs.info('New Case Watchlist with added values: ' + caseArrayAddedValues); // [3,4,5,8,1,2]
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.