update the ritm state to closed confirmed if all sctasks corresponding to the ritm are closed

anayna
Tera Contributor

I have a query how can we update the value of the ritms which are in progress even when all the sctasks related to those ritms are closed confirmed?

 

6 REPLIES 6

Ashok76
Tera Contributor

Hi Anayna,

 

Use a 'Wait for Condition' in existing Workflow

Assuming Workflow is in sc_req_item table

Ashok76_0-1668604496306.png

In the Condition script have a condition like below

var ValidateOpenTask = new GlideRecord('sc_task');
ValidateOpenTask.addQuery('request_item.number',current.number);
ValidateOpenTask.addQuery('state','NOT IN','3,4,7,8');
ValidateOpenTask.query();
if(ValidateOpenTask.next())
{
answer = false;
gs.log('Tasks is active' + ValidateOpenTask.number);
}else{
answer = true;
}

then use Set values to Update RITM record

Ashok76_1-1668604750573.png

 

or

Use BR:

Run an After Update Business Rule in SC TASK table - each time a task related to specific RITM gets updated, this BR will validate all related tasks and later on if all tasks are in closed state, will update respective RITM

 

var ValidateOpenTask = new GlideRecord('sc_task');
ValidateOpenTask.addQuery('request_item.number',current.request_item.number);
ValidateOpenTask.addQuery('state','NOT IN','3,4,7,8');
ValidateOpenTask.query();
if(ValidateOpenTask.next())
{
gs.log('Tasks is active' + ValidateOpenTask.number);
}else{
var grRitm = new GlideRecord('sc_cat_item');
grRitm.addQuery('number',current.request_item.number);
grRitm.query();
if (grRitm.next()) {
grRitm.setValue('state','3');
grRitm.update();
}

}

 

 

If SC Tasks are already in closed state, then please go for fix script/manual update

 

Regards,

Ashok

 

 

 

anayna
Tera Contributor

hi,

i need a fix script to update the ritms which are in progress state and all their corresponding sc_tasks are closed confirmed.for eg if i have an ritm in progress state and all its 3 sctsaks are closed then my ritm should get closed confirmed. but if still one task is open then i  should not update it to close confirmed

Hello Ananya,

I don't think the case that you are asking is possible at all if you are using workflow or flows to close the RITMs if tasks already close complete. Still in some case if you need to do it manually you can use the below fix script. As a beginner i tried let me know if this works for you

 

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('state=2'); //getting all the RITM with Workinprogress
gr.query();
while (gr.next()) {

var ac = gr.number;
var ab = new GlideRecord('sc_task');  // quering task related to the RITM
ab.addQuery('request_item.number', ac);
ab.query();
if (ab.next()) {       //enters the loop is only the RITM has tasks
var i = 0;
while (ab.next()) {
if (ab.state != 3) {     //check if state is not closed increase the value of i
++i;
}
}
if (i == 0) {   // if all the task are closed then i will be 0
gr.setValue('state', 3);
gr.update();
}
}
}

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Before 'End' activity you can easily add 'Set Value' activity and set state of RITM accordingly.

MusabRasheed_0-1668605484690.png

 

Please hit like and mark my response as correct if that helps
Regards,
Musab