Watch list on case showing different users than users added in the watch list.

Apurva Jogal
Kilo Sage
Hi
For below code snippet when I create a case, it adds different users than the users in the watch list variable. 
I added logs for the value it shows the correct sys_ids of the users.

There are no other business rules for the watch list field on Case table.
Please share your suggestions that can guide me in the right direction.
Thanks in advance.
 
(function executeRule(current, previous /*null when async*/ ) {
 
    var watch_list = '';
    var currentList = current.watch_list;
   
    var gr = new GlideRecord('sn_customerservice_team_member');
    gr.addQuery('account', current.account);
    gr.query();
    while (gr.next()) {
        if (currentList.indexOf(gr.user) == -1) {
            watch_list = watch_list + ',' + gr.user;
        }

    }
    if (currentList == '') {
        // watchlist empty, add users
        current.watch_list = watch_list;
    } else {
        // watchlist have existing users, add users at the end
        current.watch_list = currentList + ',' + watch_list;
    }

})(current, previous);
4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Always force sys_ids to a string when pushing them to an array or adding them to a string variable with toString() or getValue.

watch_list = watch_list + ',' + gr.user.toString();

If you are still getting unexpected results, add some logs to confirm the records and users returned by the GR, and the changing value of watch_list if necessary until you see where it's going wrong.

Hi @Brad Bowman  

Thank you for responding. 

When I log the watch_list is has the right sys_ids when I assign that to current.watch_list on case it shows different users. 

That's really odd, but there must be an explanation.  If you log watch_list right before the last if block, and current.watch_list at the end, both logs contain the expected values?  Is this a BR running before Insert?  Are the users from watch_list and current.watch_list included but there are extra, or are all of the users different?

Thank you for your suggestion, 
It is working odd for a particular account but working fine for rest of them.