Close the Requested Item record when all the associated Catalog Tasks are closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 01:41 AM
Requirement: Requested Item should be closed when all the respective catalog tasks are closed.
1. Create a Business rule on Catalog task (sc_task) table
2. Condition: Catalog task is closed complete
3. Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 01:54 AM
Or you can use the flow that creates the catalog tasks to close the RITM once the last task have been closed ?
The above script doesnt make sense to use
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 04:49 AM
Hi @Simon Christens,
The above script does make sense. It works absolutely fine. Yes, you are correct it can be done using flow designer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 06:47 PM
Hi @Simon Christens,
Though the requirement can be done with the flow, I need a info message when the catalog task associated to a particular ritm is not closed. This is not possible using flow designer as flows are async. So, according to the requirement it is recommended to use a after update business rule rather than flow designer. (Using Logs can only create a record but doesn't display the message on the form level)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 03:43 AM
Hello @shivatmika_19
Please try this script:
(function executeRule(current, previous /*null when async*/) {
// Fetch the associated Requested Item (RITM)
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.request_item)) {
// Check if any open tasks remain for the RITM
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', current.request_item); // Match the RITM
tasks.addQuery('state', '!=', 3); // Replace '3' with the state value for Closed Complete
tasks.query();
if (!tasks.hasNext()) {
// No open tasks remain, close the RITM
ritm.state = 3; // Replace '3' with the appropriate Closed Complete state value
ritm.update();
}
}
})(current, previous);
"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar