Adding user to case watchlist

Navneet Attri
Tera Contributor

Hi,

 

I have a request where we need to add 2 users to watchlist by default to new case created for a pareticular account(assume X) everytime .I was able to fulfill that with a buisness rule w/o any script .

Now we have to append the BR logic to accomadate the below points .

 

a) These 2 Contacts are added to WList in any scenario that the Case updates to "X" & anyone who already was on the WList before this update event remains on the WList.
b) These 2 Contacts are removed from WList if Case 'Account' is changed FROM "X" & anyone who already was on the WList before this update event remains on the WList.

 

 

This is the script logic I have in place , can you please help me append it to fulfill above 2 points .

 

var wl = current.watch_list.toString();
 
var wll = (wl + "," + "sys_id 1st user & sys_id 2nd user");
 
var wlArray = wl1.split(',');
 
    var arrayUtil = new ArrayUtil();
 
    var finalArray = arrayUtil.unique(wlArray);
    current.watch_list = finalArray.toString();
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If you're not already taking this approach, it sounds like you want to keep the Business Rule w/o a script before Insert, then create another one before Update with the Filter Conditions Account changes to handle these 2 scenarios.  Your script on this BR would look more like this:

var usr1 = 'sys_id 1st user';
var usr2 = 'sys_id 2nd user';
var wlArr = current.watch_list.toString().split(',');

//add 2 Contacts to WL if Account changes to X
if (current.account == 'dc5dd0843bc02300bfe04d72f3efc41e') { //sys_id of account X
    wlArr.push(usr1);
    wlArr.push(usr2); 
    var arrayUtil = new ArrayUtil();
    var finalArray = arrayUtil.unique(wlArr);
    current.watch_list = finalArray.join(',');
}
//remove 2 Contacts from WL if Account changes from X
if (previous.account == 'dc5dd0843bc02300bfe04d72f3efc41e') { //sys_id of account X
    wlArr.splice(wlArr.findIndex(usr1), 1);
    wlArr.splice(wlArr.findIndex(usr2), 1);
    current.watch_list = wlArr.join(',');
}

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

If you're not already taking this approach, it sounds like you want to keep the Business Rule w/o a script before Insert, then create another one before Update with the Filter Conditions Account changes to handle these 2 scenarios.  Your script on this BR would look more like this:

var usr1 = 'sys_id 1st user';
var usr2 = 'sys_id 2nd user';
var wlArr = current.watch_list.toString().split(',');

//add 2 Contacts to WL if Account changes to X
if (current.account == 'dc5dd0843bc02300bfe04d72f3efc41e') { //sys_id of account X
    wlArr.push(usr1);
    wlArr.push(usr2); 
    var arrayUtil = new ArrayUtil();
    var finalArray = arrayUtil.unique(wlArr);
    current.watch_list = finalArray.join(',');
}
//remove 2 Contacts from WL if Account changes from X
if (previous.account == 'dc5dd0843bc02300bfe04d72f3efc41e') { //sys_id of account X
    wlArr.splice(wlArr.findIndex(usr1), 1);
    wlArr.splice(wlArr.findIndex(usr2), 1);
    current.watch_list = wlArr.join(',');
}