Auto Populate Email In Watchlist

Priya1111
Tera Contributor

HI Team, 

I need an Email ID to be auto populated into watchlist when a particular priority and assignment group were selected.

I have tried using business rule with Before and Insert &Update.

But the Issue is I am getting the email id populated for multiple times when Incident is updated.

 

var email = " ";
var wl = current.watch_list;
if (current.watch_list.indexOf(email) > -1) {
return;
}
if (current.watch_list == "") {
current.watch_list = email;
} else if (current.watch_list == email) {
return;
} else
current.watch_list += "," + email;

 

 

Any kind of help would be grateful

Thanks in advance!

4 REPLIES 4

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Priya1111 

To get assignment group users try below BR

GunjanKiratkar_0-1671789739053.png

 

Script :-

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

    // Add your code here
    var grpMembers = new GlideRecord("sys_user_grmember");
    grpMembers.addQuery("group", current.assignment_group);
    grpMembers.query();
    while (grpMembers.next()) {
        var user = (',' + grpMembers.user);
        current.watch_list += user;
    }

})(current, previous);

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

HI @Gunjan Kiratkar 

Thanks for the reply!

But I need an Email which is not in user table to be auto-populated into watchlist.

Hi @Priya1111 ,

From where you are getting email list? also is it comma separated list?


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

@Gunjan Kiratkar 

I need only one email to be auto populated into watchlist without creating duplicate entries when updated multiple times.

 

I have taken as var email = " example@abc.com";  in this way.