- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 04:43 PM
i need to write a business rule where, when all the catalog tasks of the catalog item are closed complete then the catalog request item is also closed? Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 05:17 PM
If you are opening all the tasks from workflow, then insert a join activity in front of all catalog task activities. The join activity will wait for all the tasks to be closed. Then insert a set activity to set the state of RITM to closed complete. This should be the preferred approach.
If for some reason you need a BR to close the RITM, use the following code in your after BR
In the condition field of the BR, use
''+current.request_item.cat_item == "060f3afa3731300054b6a3549dbe5d3e" // sys_id of the catalog item so that it only triggers on for a specific catalog item
Please mark my answer as correct/helpful, if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 09:52 AM
Hi Sukhbir,
I've got a similar request request/issue from a customer. They are creating manual tasks and when one gets closed, the RITM closed too even if there are other active tasks when it should only close when all tasks are completed. Would this work in my case too? They also want to be able to close a RITM when it has active tasks - not best practice perhaps but this is their requirement.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 12:41 PM
Hi Amelie
I can see flaw in their process. The RITM should not close until all tasks are closed. Tasks are opened under the umbrella of RITM. You can suggest them to correct it.
This code may not work exactly because there is a parallel piece of code/workflow which is allowing the RITM closure when a task is closed. You need to block that and this code may start working.
Can you share more details about the workflow and requirements?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 05:54 PM
Hi Sukhbir,
This is my recent post
https://community.servicenow.com/community?id=community_question&sys_id=fdd397cbdb928910bb4a474d1396198d
The customer is using the Item Designer Fullfilment workflow and the functionality is per OOTB. I'm not sure why RITM is getting closed when manual tasks are closed, as this used to work fine before when the only tasks of a RITM were the ones created in the workflow. I thought the workflow doesn't pick up the manual tasks but somehow it does and doesn't check if there are other active tasks.
This customer in particular is quite difficult, I've offered a simple solution to check for active tasks when the state of a RITM changes and abort the action if there are, but they said they still want to be able to close a RITM even if it has open tasks even if it's not best practice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 05:51 PM
Hi saini,
If you want to write Business Rule to achieve this requirement,
Then you need to Create After Business Rule on Catalog Task.
Please Check and Let us know
Thanks 🙂
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 05:56 PM
Here is the script for
Create After Business Rule on Catalog Task.
(function executeRule(current, previous)
{
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.request_item);
gr.query();
if (gr.next())
{
gr.state=3; //3 is my Closed COmplete valu, add yours
gr.update();
}
})(current, previous);
If my answers is Helpful to you, Please mark as Correct Answer/Helpful
Please check and Let us know.
Thanks 🙂
Shakeel Shaik 🙂