how to set sc task state based on ritm state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 07:58 AM
I have to set sc task state to "Closed incomplete" when RITM state updated to closed through the workflow, if there is any sc tasks are still opened i need to set state to "Closed incomplete".
can any one help me on this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 08:12 AM
Hello,
You can create an "after" business rule for the sc_req_item table and use the condition that if the state is 'x', then use the advanced checked and advanced tab and use script to close the sc_task records still open:
var gr = new GlideRedcord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
gr.setValue('state', 'closed_value');
gr.work_notes = gr.number + " closed systemically due to " + gr.request_item + " being closed.";
gr.update();
}
Please replace closed_value above with the appropriate state value you want to set the SCTASK(s) to.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 08:23 AM
Hi,
Why would RITM get closed before SC Task getting closed? Please check this with your business team
You can use flow designer for this with no script
1) Flow triggers when RITM State Changes to Closed
2) Then use Lookup Record on sc_task for this RITM
3) Then use For Each Action to iterate over those records
4) Use Update Record action and update the State field for each of those records
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader