Issue in closing RITM for parallel Tasks

Michael51
Tera Guru

Hello all,

I have an requirement to close RITM when all the Respective Tasks get closed , So here is our workflow behaves interms of creating Task

1. Workflow Will create 2 Tasks , Initially Single Task gets created post completing the initial task another task gets opened 

 

In order to close RITM I have written BR on Sc_task table and it is on after update 

 

 

 

    /* var count = 0;
    var tasks = new GlideRecord('sc_task');
    tasks.addQuery('request_item', current.request_item);
    //tasks.addQuery('active',true);//added
    tasks.query();
    //if(!task.next()){//added
    var taskcount = tasks.getRowCount();
    while (tasks.next()) {
        gs.info("passing into 1if loop");
        if (tasks.state == 3 || tasks.state == 4 || tasks.state == 7) {
            count++;
        }
    }
    gs.info('taskcount' + '' + count + 'yesbank');
    if (count == taskcount) {
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('sys_id', current.request_item);
        gr.query();
        if (gr.next()) {

            gr.state = 3;

            if (current.state == 3 || current.state == 7)
                gr.state = 3;
            else if (current.state == 4)
                gr.state = 4;
            gr.update();
        }
    }

 

 

 

 

here the issues is it is working for Single task and as soon as initial task gets closed RITM is getting closed but it s not waiting for next Task to complete , here I want to validate all the Tasks to get completed and proceed with RITM Closure 

Can all help with your inputs on this 

( I want to acheive this BR instead of adding Runscript in Workflow Since we want to work globally (we have lot of workflows)

@Ankur Bawiskar  

6 REPLIES 6

@Michael51 

try to debug further by adding logs in your BR

the BR script I shared should work fine and close the RITM only when all the sc_tasks are closed for the RITM belonging to current task

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mike_R
Kilo Patron
Kilo Patron

Why don't you just add a step at the end of your workflow to close the RITM. (set the state = closed complete)