have to create a business rule to close the RITM and REQ if the all related tasks got closed.

lakng
Tera Contributor

the issue here is , few requests are not getting closed.

so i want to create a busienss rule to check all the related tasks are got closed or not.

if all closed it has to close the RITM and REQ.

if not it should not execute.

please help me with the sample code.

it has to check manual tasks as well.

6 REPLIES 6

Chavan AP
Tera Guru

sample script here. You can modify it as per your req.

Script:table "sc_task" and trigger the BR only for the condition state is closed incomplete.

closeItemIfRequired();

function closeItemIfRequired(){
  // check to see if any of our peers are currently *not* closed
  var gr = new GlideRecord('sc_task');
  gr.addQuery('request_item', current.request_item);
  gr.addQuery('active', true);
  gr.query();
  if (!gr.next()) {
        // no peer task is currently open
        var sc_req_item = new GlideRecord('sc_request_item');

        sc_req_item.addQuery('sys_id', current.request_item);

        sc_req_item.query();

        if(sc_req_item.next())
  {
  //update the field of sc_req_item
                sc_req_item.update();
}}}
 


Please mark reply as Helpful/Correct, if applicable. Thanks!

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Chavan AP
Tera Guru

This should be done via workflow. IN workflow after task activity you should check the state of task which just got closed.

If the state is closed complete then use set Value activity in workflow to set state of RITM to closed complete else in NO flow of If use set value where you will set state to closed incompleted.


OOB once all ritm are closed to either incomplete or complete REQ will be closed automatically.

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****