If RITM state is closed complete then REQ should also closed complete

Shiva prasad t
Tera Guru

I need to update the REQ state to closed complete when RITM state is closed complete.

currently if state of sc_task is closed then RITM state is setting as closed complete.

So as well as RITM i need to closed Request also if RITM is closed.

Any help will be appreciated.

Thank you,

Shivprasad

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then add the logic there itself where you are closing RITM

update as this

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

    // Add your code here
    var closedCompleteCount = 0;
    var closedInCompleteCount = 0;
    var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.request_item); 
    gr.query();
    var totalCount = gr.getRowCount();
    while(gr.next()){
        if(gr.state == 3){
            closedCompleteCount++;
        }
        if(gr.state == 4){
            closedInCompleteCount++;
        }
    }

    var ritm = current.request_item.getRefRecord();
    var req = current.request.getRefRecord();
    if(totalCount == closedCompleteCount){
        ritm.state = 3;
        ritm.update();
        req.state = 3;
        req.update();
    }
    if(closedInCompleteCount > 0){
        ritm.state = 4;
        ritm.update();
        req.state = 3;
        req.update();
    }

})(current, previous);

Regards
Ankur

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

View solution in original post

12 REPLIES 12

Aman Kumar S
Kilo Patron

Hi @Shiva prasad,

You already have an OOB BR that takes care of it, you just also need to set the stage to complete or incomplete.

Close Parent if Required is on Requested item table, check conditions of the BR for better understanding

find_real_file.png

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then add the logic there itself where you are closing RITM

update as this

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

    // Add your code here
    var closedCompleteCount = 0;
    var closedInCompleteCount = 0;
    var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.request_item); 
    gr.query();
    var totalCount = gr.getRowCount();
    while(gr.next()){
        if(gr.state == 3){
            closedCompleteCount++;
        }
        if(gr.state == 4){
            closedInCompleteCount++;
        }
    }

    var ritm = current.request_item.getRefRecord();
    var req = current.request.getRefRecord();
    if(totalCount == closedCompleteCount){
        ritm.state = 3;
        ritm.update();
        req.state = 3;
        req.update();
    }
    if(closedInCompleteCount > 0){
        ritm.state = 4;
        ritm.update();
        req.state = 3;
        req.update();
    }

})(current, previous);

Regards
Ankur

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

Hi @Ankur Bawiskar 

 

If we are having 3 tasks one task in Close Complete and 2. Close Incomplete and 3. open 

but with this condition when one task is close incomplete then the related request and RITM are getting closed .

   if(closedInCompleteCount > 0){
        ritm.state = 4;
        ritm.update();
        req.state = 3;
        req.update();
    }