How to update a user related list record when a watch list external user gets added or removed
- 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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 10:05 PM
@IB98
1. Create a Related Party Configuration for external users.
2. Create a Business Rule runs on updating sn_customerservice_case record, if the watch_list field changes, create a Related Party Configuration record with the above newly created type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 01:56 AM
I HAVE CREATED THE RECORD BUT I MIGHT NEED HELP WITH THE BUSINESS RULE SCRIPT TO UPDATE OR ADD THE USERS. TO THE RELATED LIST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 09:24 PM
@IB98 , try create an after BR on watch_list changes.
(function executeRule(current, previous /*null when async*/) {
const externalPartyConfig = "<sys_id external party config>";
var watchListArr = current.watch_list.split(",");
var externalPartiesArr = [];
watchListArr.forEach(function(party){
var grUserRole = new GlideRecord('sys_user_has_role');
grUserRole.addQuery("user", party);
grUserRole.addEncodedQuery("role.nameSTARTSWITHsnc_external");
grUserRole.query();
if(grUserRole.next())
{
externalPartiesArr.push(party);
}
});
var grRelatedParty = new GlideRecord("sn_customerservice_related_party");
grRelatedParty.addQuery("case_record", current.sys_id);
grRelatedParty.addQuery("party_config", externalPartyConfig);
grRelatedParty.query();
while(grRelatedParty.next()){
var partyId = grRelatedParty.user + "";
if(partyId && !externalPartiesArr.includes(partyId))
{
grRelatedParty.deleteRecord();
} else if (partyId && externalPartiesArr.includes(partyId))
{
externalPartiesArr = externalPartiesArr.filter(function (party) {
return party !== partyId;
});
}
}
externalPartiesArr.forEach(function(party){
var grRelatedParty = new GlideRecord("sn_customerservice_related_party");
grRelatedParty.initialize();
grRelatedParty.setValue("case_record", current.sys_id);
grRelatedParty.setValue("party_config", externalPartyConfig);
grRelatedParty.setValue("user", party);
grRelatedParty.insert();
});
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 11:18 PM
you can use after update business rule on case table and then modify the watch list
Business Rule: After Update on sn_customerservice_case
Condition: Watch List Changes
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var rec = new GlideRecord('sn_customerservice_related_party');
rec.addQuery('case_record', current.sys_id);
rec.query();
if (rec.next()) {
var currentUsersArr = rec.watchListField.toString().split(',');
var watchListFromCaseArr = current.watch_list.toString().split(',');
var arrayUtil = new global.ArrayUtil();
var finalArr = arrayUtil.concat(currentUsersArr, watchListFromCaseArr);
finalArr = arrayUtil.unique(finalArr);
rec.watchListField = finalArr.toString();
rec.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader