REQ/RITM/TASK watch list

Brendan Hallida
Kilo Guru

Hi all,

I have a Business rule which updates the request and request item watch list whenever the watch list for the catalog task is changed.   This includes removing users from the watch list.

Table: sc_task

When to run: Before, Insert, Update

(function() {

  //get the gliderecord for the parent request

  var req = new GlideRecord('sc_request');

  if (req.get(current.request)) {

          req.watch_list = current.watch_list;

    req.update();

  }

  //get the gliderecord for the parent request item

  var reqitem = new GlideRecord('sc_req_item');

  if (reqitem.get(current.request_item)) {

          reqitem.watch_list = current.watch_list;

    reqitem.update();

  }

})();

This works great for single REQ/RITM/Tasks (which is all we have at the moment) however I can see the need for multiple tasks coming in the not too distant future, and would like to plan for that with any scripts i may be placing into the environment.

Does anyone know how I could approach this with the business rule above?

Cheers,

Brendan

1 ACCEPTED SOLUTION

Brendan Hallida
Kilo Guru

Hi all,



I ended up going with using the request watch list on the catalog task form, and using the request watch list for all the notifications.



To get the request watch list onto the task form working properly, I needed to use parent.parent.watchlist, however I needed to create a BR that sets the REQ as the RITM's parent.   Sometimes they don't make it easy.



REQ RITM parent relationship


View solution in original post

8 REPLIES 8

Kalaiarasan Pus
Giga Sage

You need to query the sc_task table and get all the tasks that are related to the current RITM.



var gr_tsk = new GlideRecord("sc_task");


gr_tsk.addQuery('request_item', current.request_item);


gr_tsk.query();


if (gr_tsk.next()) {


get all the watch list of all task.


}


Manoj Kumar16
Giga Guru

If you want to update multiple tasks of an ritm if one of the task's watchlist is changed then you need to query all the tasks and update....



var gr= new GlideRecord('sc_task');


gr.addQuery('request_item',current.request_item);


gr.query();


while(gr.next())


{


if(gr.watch_list!=current.watch_list)


{


gr.watch_list=current.watch_list;


gr.update();


}


}



this will update all the other tasks associated with same ritm...


Brendan Hallida
Kilo Guru

Hi Kalai and Manoj,



will these also update the request as well?



also Kalai - is the code you are suggesting to add to my existing code?



I am not the greatest with Javascript, but I have come a fair way since I started...


Yes .. replace your existing code.