Need to write script to close RITM if all the associated multiple tasks are closed

Kishan4
Mega Expert

HI All,

 

We had an issue with few of the RITMs, where RITMs with multiple tasks are not closed even if all their associated catalog tasks are closed. The requirment is to identify all those RITMs by getting them into log  and close them.

 

Note: All those RITMs have multiple tasks each.

1 ACCEPTED SOLUTION

Kach
Giga Contributor

Run this code in a fix script. Mark as helpful if it helped.

 

var ritm = new GlideRecord("sc_req_item");
//check for all active RITM
ritm.addEncodedQuery("active=true");
ritm.query();

while (ritm.next()) {
   
    var task_incomplete = 0;
    var tasks = new GlideRecord('sc_task');
    tasks.addQuery('request_item', ritm.sys_id);
    tasks.query();
    while (tasks.next()) {
        //check is task is ative
        if (tasks.active == true) {
            task_incomplete = 1;
        }
    }
    //close RITM if all tasks are inactive
    if (task_incomplete == 0) {
        //close all RITM with no active Tasks
        ritm.setValue('active', false);
        ritm.update();
    }
}

View solution in original post

9 REPLIES 9

palanikumar
Mega Sage

Hi,

We also face issue in few items. Even though all the SC tasks are closed, RITM remains as in progress. You can add activity at the end of workflow and set state as complete before it end. 

Thank you,

Palani

Thank you,
Palani

Kach
Giga Contributor

Run this code in a fix script. Mark as helpful if it helped.

 

var ritm = new GlideRecord("sc_req_item");
//check for all active RITM
ritm.addEncodedQuery("active=true");
ritm.query();

while (ritm.next()) {
   
    var task_incomplete = 0;
    var tasks = new GlideRecord('sc_task');
    tasks.addQuery('request_item', ritm.sys_id);
    tasks.query();
    while (tasks.next()) {
        //check is task is ative
        if (tasks.active == true) {
            task_incomplete = 1;
        }
    }
    //close RITM if all tasks are inactive
    if (task_incomplete == 0) {
        //close all RITM with no active Tasks
        ritm.setValue('active', false);
        ritm.update();
    }
}

mkrishnasundar
Giga Expert

This issue could happen if your SCTASKs active flag didn't change to "false" even though their state is Closed Complete or Closed Incomplete or Closed Cancelled. If you debug onto that flag, you can notice this.

System will come to know task's lifecycle end only if it's active flag changed to false. So this could be your root cause.

Check your instance, for any script (probably Business Rule) might have collision with the other script.

Regards,
Krishna
https://www.linkedin.com/in/mkrishnasundar/

WE HAVE SAME issue how can we check if Flag did not change to false ? or debug it ?

do i need to modify Business rule "mark closed" which runs on "task" table which sets the active flag to false