Auto add user to watchlist

juliochacon23
Tera Expert

Hi, I am trying to setup a business rule to auto add a user (Joe Smith) to a watchlist when the incident is assigned to the certain assignment group.   This is what I have but it is not working.   Also this should append the user not remove any existing users to the watchlist.

Any help much appreciated.   Thanks

-Julio

find_real_file.png

addToWatchList();

function addToWatchList() {

if(current.assignment_group.getDisplayValue() == 'Finance Support') {

  current.watch_list == 'Joe Smith';

}

}

find_real_file.png

1 ACCEPTED SOLUTION

andrewpilachows
Kilo Guru

*Have to research



"==" is comparison, "=" is assignment, and "+=" is a shorthand for append.   You need to check if watch_list is empty before doing an append or an assignment though.   In order to not be hardcoding "Joe", use a system property (sys_properties.list).   This will allow you to quickly change it without having to go back and update a script and push the set through testing.   Say the name of the property is "incident.auto_watch" as a string value.



var watchers = gs.getProperty('incident.auto_watch');


if (current.watch_list.nil())


    current.watch_list = watchers;


else


    current.watch_list += ',' + watchers;



Use the filter function to select assignment group instead of the script.


find_real_file.png



Your business rule should also be wrapped in an executeRule function which should be automatically generated.


find_real_file.png


View solution in original post

9 REPLIES 9

andrewpilachows
Kilo Guru

*Have to research



"==" is comparison, "=" is assignment, and "+=" is a shorthand for append.   You need to check if watch_list is empty before doing an append or an assignment though.   In order to not be hardcoding "Joe", use a system property (sys_properties.list).   This will allow you to quickly change it without having to go back and update a script and push the set through testing.   Say the name of the property is "incident.auto_watch" as a string value.



var watchers = gs.getProperty('incident.auto_watch');


if (current.watch_list.nil())


    current.watch_list = watchers;


else


    current.watch_list += ',' + watchers;



Use the filter function to select assignment group instead of the script.


find_real_file.png



Your business rule should also be wrapped in an executeRule function which should be automatically generated.


find_real_file.png


Try creating the util function as described here so you can re-use it across scripts.   The system property you create should contain a single sys id or a comma separated list of sys ids to be added.


Managing Glide Lists



var auto_watchers = gs.getProperty('incident.auto_watch').split(',');


var lu = new ListUtil(current.watch_list);



for (var i = 0; i < auto_watchers.length; i++) {


      lu.addToList(auto_watchers[i].trim());


}



current.watch_list = lu.getList();


shloke04
Kilo Patron

Hi,



As per your scenario, if you want to add a Specific User to the Watch List say when your Assignment Group Changes then you need to write a Before Update Business Rule with Conditions as "Assignment Group ChangesTo "Group Name" and with the below script:



Script:



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



  // Add your code here


  var user_name = '62826bf03710200044e0bfc8bcbe5df1';     // Static Sys_ID of User which needs to be added to Watch List


  var currentList = current.watch_list;


  if(currentList.indexOf(user_name) > -1)


  {


  gs.addInfoMessage("User already in the WatchList, not added");


  }


  else


  {


  current.watch_list += ',' + user_name;


  gs.addInfoMessage("Added " + user_name.getDisplayValue() +" to the WatchList");


  }




})(current, previous);




find_real_file.png



find_real_file.png



Say Suppose if you want to make this Dynamic, for example whenever the Assignment Group changes, you want to add the Users to Watch List who ever is selected in Assigned To field based on the Assignment Group then you need to modify your script as below:



Script:



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



  // Add your code here


  var user_name = current.assigned_to;     // Get the Assigned to User selected


  var currentList = current.watch_list;


  if(currentList.indexOf(user_name) > -1)


  {


  gs.addInfoMessage("User already in the WatchList, not added");


  }


  else


  {


  current.watch_list += ',' + user_name;


  gs.addInfoMessage("Added " + user_name.getDisplayValue() + "to the WatchList");


  }




})(current, previous);



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke






Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Thanks, this seems to work only if the incident is updated, but if I create a ticket from the self service page it does not auto add the user to the watchlist even if the tickets comes in to the correcty assignment group.   Any ideas?



Thanks


-Julio