Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Add person to watch list on Incident

todd_verrastro
Giga Contributor

Hi,

I have a requirement to add a specific person to the Incident watch list when the "Caller" field is populated with certain users. Is this best done with a business rule or client script?

Also, how would you configure it?

Thanks in advance!

Todd

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

From a performance perspective unless you need it client side as the user is filling out the incident form to populate it, it is best to run it server side via a business rule.



Is this a hard coded person or is this person an attribute of these certain callers?



Create an advanced business rule that runs before insert/update and set the appropriate conditions via condition builder, and then a script like the following should work.   This code will work even if the watch list is already populated.



var userToAdd = "sys_id_of_the_user"; //This is the SysID of the user to add to the watch list



var watch_list = current.watch_list.toString().split(",");



if (watch_list.toString().indexOf(userToAdd) == -1) {


      watch_list.push(userToAdd);


      current.watch_list = watch_list.join(",").toString();


}


View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Todd,



Create a BEFORE business rule, define filter conditions as per your req and the script will be


current.watch_list=current.watch_list+','+current.caller_id;


Reference:


Business Rules - ServiceNow Wiki


Business Rule to Add User to Watch List if Caller is VIP


Mike Allen
Mega Sage

I would have a before insert/update BR that says,



if(user in <certain users>){


current.watch_list += specific_person;


}


Nick Simonelli1
Mega Expert

There is also some other good info (actually credited to the same 2 people who answered above) at this link. It may be helpful to you.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

From a performance perspective unless you need it client side as the user is filling out the incident form to populate it, it is best to run it server side via a business rule.



Is this a hard coded person or is this person an attribute of these certain callers?



Create an advanced business rule that runs before insert/update and set the appropriate conditions via condition builder, and then a script like the following should work.   This code will work even if the watch list is already populated.



var userToAdd = "sys_id_of_the_user"; //This is the SysID of the user to add to the watch list



var watch_list = current.watch_list.toString().split(",");



if (watch_list.toString().indexOf(userToAdd) == -1) {


      watch_list.push(userToAdd);


      current.watch_list = watch_list.join(",").toString();


}