- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 05:13 PM
Hello Community,
I’m designing a flow in ServiceNow where I have three tasks using do the following in Parallel. (see screenshot)
- (x)
- (y)
- (z)
The z task cannot be closed unless either x or y tasks are in the " Close Complete" state. If either x or y tasks are still open , the "Close Task" button for the (z) task should be disabled.
How can I implement this in ServiceNow? Should I use a UI Action, Business Rule, or flow for this?
Thanks in advance for your help!
Regards,
Beyza
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 10:06 PM
Hi @beycos ,
You can create before business rule on task table and use below script.
var grTask = new GlideRecord('task'); // Replace 'task' with the appropriate table name
grTask.addEncodedQuery('parent='+current.parent+'^stateIN-5,1,2^sys_id!='+current.sys_id+''); // Fetch tasks X and Y
grTask.query();
if (grTask.next()) {
gs.addErrorMessage('Task Z cannot be closed until either Task X or Task Y is in the "Close Complete" state.');
current.setAbortAction(true);
}
When to run condition
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 09:51 PM
are you sure the group names are correct?
BR should be before update
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 05:28 PM
Seems updating the existing UI action is needed. but how the 3 tasks are related is not specified, are x and y child task of z?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 03:43 AM
Hello Bert_c1,
X, Y, and Z are all child tasks of the same parent task.
Regards,
Beyza
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 07:09 PM
it should be a UI action condition to hide the close button
OR
you can use before update BR and check what's the status of task X and Y
If any 1 is open then abort the business rule
BR Condition: current.State Changes to Close Complete && current.request_item.cat_item.name == 'Your Item Name'
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.request_item);
gr.addActiveQuery();
gr.addEncodedQuery('short_descriptionINTaskXShortDesc,TaskYShortDesc'); // give here the unique short description of task x and task y
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('You cannot close this task as either Task x or Task y is open');
current.setAbortAction(true);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 03:22 AM
Thank you for your response Ankur. Could you please check this script?? this is Before update BR. Thank you
not working atm.