update the ritm state to closed confirmed if all sctasks corresponding to the ritm are closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 04:25 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 05:20 AM - edited 11-16-2022 05:20 AM
Hi Anayna,
Use a 'Wait for Condition' in existing Workflow
Assuming Workflow is in sc_req_item table
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 08:41 AM - edited 11-16-2022 08:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 10:13 AM
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();
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 05:31 AM
Hello,
Before 'End' activity you can easily add 'Set Value' activity and set state of RITM accordingly.
Regards,
Musab