How to update a user related list record when a watch list external user gets added or removed
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 01:55 PM - edited 05-27-2025 02:11 PM
Hello,
is there a way to update a sn_customerservice_related_party related list record when the external users get added/ removed from a sn_customerservice_case watch list ? Thank you!
10 REPLIES 10
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 08:06 PM
I took it the other way.
So you can have whenever watch list is updated/removed the record should be created or removed
then use this
BR Condition etc remains the same
(function executeRule(current, previous) {
// Convert comma-separated watch_list to arrays
var prevWatchers = previous.watch_list ? previous.watch_list.split(',') : [];
var currWatchers = current.watch_list ? current.watch_list.split(',') : [];
// Find added and removed users
var added = currWatchers.filter(function(x) { return prevWatchers.indexOf(x) === -1; });
var removed = prevWatchers.filter(function(x) { return currWatchers.indexOf(x) === -1; });
// Add related party records for new watchers
added.forEach(function(userId) {
var gr = new GlideRecord('sn_customerservice_related_party');
gr.initialize();
gr.case_record = current.sys_id; // Adjust field name as needed
gr.user = userId; // Adjust field name as needed
gr.insert();
});
// Remove related party records for removed watchers
removed.forEach(function(userId) {
var gr = new GlideRecord('sn_customerservice_related_party');
gr.addQuery('case_record', current.sys_id); // Adjust field name as needed
gr.addQuery('user', userId); // Adjust field name as needed
gr.query();
while (gr.next()) {
gr.deleteRecord();
}
});
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader