Collaborator removal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 10:22 AM
I can see multiple cases that have me tagged as a collaborator, many of which are in the 'Closed complete' status. Is there a way to mass remove myself as a collaborator and move them out my collaborator list or do I need to delete myself from each individual case?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 06:14 PM
Hey @amandahende -
I would say you could do so through the list view edit, but Collaborators is not an editable field from there. Unless you adjust/add some ACLs to allow the field to be edited from the list view.
Otherwise, you could probably get this done through a background/fix script using an encoded query.
The fix script you could use could be this (note: the query is running on dynamic from my PDI, you may need to grab your own query from the list view):
List view for Collaborations:
Fix Script:
(function() {
// The encoded query to filter HR Cases where the state is 'Closed Complete' (state = 3)
// and the current user is in the collaborators field
var encodedQuery = "collaboratorsDYNAMIC90d1921e5f510100a9ad2572f2b477fe^state=3";
// Create a GlideRecord instance for the HR Case table
var hrCaseGR = new GlideRecord('sn_hr_core_case');
// Add the encoded query to the GlideRecord instance
hrCaseGR.addEncodedQuery(encodedQuery);
// Query the records
hrCaseGR.query();
// Loop through each record returned by the query
while (hrCaseGR.next()) {
// Get the current list of collaborators
var collaborators = hrCaseGR.getValue('collaborators');
// Convert the collaborators list to an array
var collaboratorsArray = collaborators.split(',');
// Get the user ID of the current user
var currentUserID = gs.getUserID();
// Find the index of the current user in the collaborators array
var userIndex = collaboratorsArray.indexOf(currentUserID);
// If the current user is found in the collaborators array, remove them
if (userIndex > -1) {
collaboratorsArray.splice(userIndex, 1);
// Join the array back into a comma-separated string
var updatedCollaborators = collaboratorsArray.join(',');
// Set the updated collaborators list back to the record
hrCaseGR.setValue('collaborators', updatedCollaborators);
// Update the record
hrCaseGR.update();
}
}
})();
Be sure to test this out in a sub-prod instance first. But I just tested in my PDI, and it worked correctly.
Notice in the encoded query, it is looking at hr cases that are in closed complete state (state=3). If this is when you want it, then you can use that.
Here I am as a Collaborator to a couple of cases (this is all Demo Data hr cases I am using):
After I run the fix script:
If this however, should become a business requirement, you could think about using the script like this in a scheduled job, that runs daily to check on the hr cases, in the closed complete state, to remove users from the collaborators field.
Hope this helps! Give it a test and let me know if it worked or not. Or if you need to change requirements.
Cheers,
-Rob
**p.s. Please remember to mark replies as Helpful and/ or Correct when appropriate**

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 06:27 PM
You could also do a business rule so that it happens automatically (much like my suggestion with the scheduled job, but this will just happen each time the hr case record changes).
You could utilize a business rule - to remove yourself from the collaborators field. Again, please not that the script I am showing you removes ONLY you. If you want it to remove anyone, just let me know and we can adjust the script to do so. But here is the business rule you can create and test with:
(function executeRule(current, previous /*null when async*/ ) {
// Ensure this Business Rule runs only when the state changes to Closed Complete
if (current.state == '3' && previous.state != '3') {
// Get the current user's ID
var currentUserID = gs.getUserID();
// Get the current list of collaborators
var collaborators = current.getValue('collaborators');
// Convert the collaborators list to an array
var collaboratorsArray = collaborators ? collaborators.split(',') : [];
// Find the index of the current user in the collaborators array
var userIndex = collaboratorsArray.indexOf(currentUserID);
// If the current user is found in the collaborators array, remove them
if (userIndex > -1) {
collaboratorsArray.splice(userIndex, 1);
// Join the array back into a comma-separated string
var updatedCollaborators = collaboratorsArray.join(',');
// Set the updated collaborators list back to the record
current.setValue('collaborators', updatedCollaborators);
// Update the record
current.update();
}
}
})(current, previous);
Give these a testing - again, the business rule will run reach time. The fix script is for a one-time correction to the record.
Cheers,
-Rob
**p.s. Please remember to mark replies as Helpful and/ or Correct when appropriate**