Close SCTASK and RITM when Request is Closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 01:48 PM
I need to close the RITM and the SCTASK associated with the Request when the Request is Closed.
How can I achieve this?
Thanks,
Mallika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 08:02 PM - edited 09-21-2023 08:40 PM
Hi @mallikabhupathi ,
You can create a business rule on sc_request table like the one below. (This might not be a best practice to close from REQ -> RITM -> Task, but if this is a requirement you can use the following.
When to Run: after Insert / Update
Condition: State :: Changes to :: Closed
Script:
(function executeRule(current, previous /*null when async*/ ) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id);
ritm.query();
while (ritm.next()) {
var sct = new GlideRecord('sc_task');
sct.addQuery('request_item', ritm.sys_id);
sct.query();
while (sct.next()) {
sct.state = '3';
sct.update();
}
ritm.state = '3';
ritm.update();
}
})(current, previous);
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 08:09 PM
Ideally SC task gets closed then RITM and REQ.
Why it's the reverse way for your case?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 09:53 PM
Hi @mallikabhupathi you can achieve it flow designer with out code with conditions below:
Thanks & Regards,
Eswar Chappa
Mark my answer correct and Helpful if this helps you 😀