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.

Business rule help to copy watch list from RITM to Task

Josh Hines
Tera Contributor

Hello,

 

I am looking for a way to pull the watch list from a new RITM into the SCTask record. I have set up a business rule to run after the Watch List changes, but am having issues getting my code to work. I would appreciate any help on getting this to work from you smart people. Thank you!

 

JoshHines_0-1696617463802.png

(function() { 

   //get the gliderecord for the parent request

   var task = new GlideRecord('sc_task'); 

   if (task.get(current.catalog_task)) { 

           task.watch_list = current.watch_list;

     task.update(); 

   }


})();

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Josh,

Since this BR is running on the sc_req_item table, 'current' refers to the RITM record that is being changed.  There is not a field on the sc_req_item table named catalog_task, so that's where your script is failing.  Something like this should work, copying the watch_list to ALL Catalog tasks that exist at the time of the update:

var task = new GlideRecord('sc_task'); 
task.addQuery('parent', current.sys_id);
task.query();
while (task.next()) {
     task.watch_list = current.watch_list;
    task.update(); 
}

View solution in original post

6 REPLIES 6

You are welcome!

Danish Bhairag2
Tera Sage

Hi @Josh Hines ,

 

Can u try the below code .

var gd = new GlideRecord('sc_task');
    gd.addQuery('request_item',current.sys_id)
    gd.query();
    while(gd.next()){
    gd.watch_list = current.watch_list;
    gd.update();
    }

 

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish