how can we add a person as a watchlist whenever he/she as tagged in comments in the workspace

poornima batchu
Tera Expert

Hi everyone,

 whenever a person is tagged in the comments in workspace is it possible to add them as a watchlist automatically...?

In the attached screenshot @poornima batchu has been tagged in the comments. My requirement is when a person is tagged he/she automatically added as a watchlist. please provide a solution to achieve this.

 

thank you.

 

find_real_file.png

1 ACCEPTED SOLUTION

chrisperry
Giga Sage

Hi there,

You can achieve your requirements with an after Insert business rule running on the live_notification table as below:

find_real_file.png

find_real_file.png

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var grTable = new GlideRecord(current.getValue('table'));
    if (grTable.get(current.getValue('document'))) {
        var recWatchList = grTable.getValue('watch_list');
        if (current.getValue('field_name') == 'comments') {
            if (recWatchList) {
                if (recWatchList.indexOf(current.getValue('user')) == -1) {
                    var watchListArr = recWatchList.split(',');
                    watchListArr.push(current.getValue('user'));
                    grTable.setValue('watch_list', watchListArr.join());
                    grTable.update();
                }
            } else {
                grTable.setValue('watch_list', current.getValue('user'));
                grTable.update();
            }
        }
    }

})(current, previous);

Result:

find_real_file.png

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

View solution in original post

1 REPLY 1

chrisperry
Giga Sage

Hi there,

You can achieve your requirements with an after Insert business rule running on the live_notification table as below:

find_real_file.png

find_real_file.png

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var grTable = new GlideRecord(current.getValue('table'));
    if (grTable.get(current.getValue('document'))) {
        var recWatchList = grTable.getValue('watch_list');
        if (current.getValue('field_name') == 'comments') {
            if (recWatchList) {
                if (recWatchList.indexOf(current.getValue('user')) == -1) {
                    var watchListArr = recWatchList.split(',');
                    watchListArr.push(current.getValue('user'));
                    grTable.setValue('watch_list', watchListArr.join());
                    grTable.update();
                }
            } else {
                grTable.setValue('watch_list', current.getValue('user'));
                grTable.update();
            }
        }
    }

})(current, previous);

Result:

find_real_file.png

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry