- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 03:29 AM - edited ‎06-13-2025 05:07 AM
Hi All,
I need help with a requirement - the requirement is on the change request form when we are moving from implement to review state if that change request has any associated change task auto or manual if the task is not either closed or cancelled the change request state should not move from implement to review state Now to fix it
I wrote a Business Rule on change_request table, before update with condition state changes to review
This is the script that I have written
How can I avoid it so that irrespective whether there is auto task or manual task the change request does not move to review state unless until all the change task are closed
And the flow is OOTB
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 04:35 AM
Hi @Harsh3842,
If you want the Flow to not be activated when BR is running then add
if (taskGR.hasNext()) {
taskGR.setWorkflow(false);// Disables the Flow on Change Task
gs.addErrorMessage("All Change Tasks must be closed or cancelled before moving to the Review state.");
current.state = previous.state; // Revert to previous state
gs.setAbortAction(true); // Block the update
}
However, you need to check if disabling the Flow doesnt hamper critical processes before moving forward.
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 03:43 AM
ensure flow is not having a race condition with your business rule
Also if your flow is trying to close the change request before the last task is fully closed, you may need to adjust the flow logic or use a short delay.
try this updated script
(function executeRule(current, previous) {
var implementState = -1; // Update with your actual "Implement" state value
var reviewState = 0; // Update with your actual "Review" state value
// Only block if moving from Implement to Review
if (current.state == reviewState && previous.state == implementState) {
// Use GlideAggregate for efficiency
var agg = new GlideAggregate('change_task');
agg.addQuery('change_request', current.sys_id);
agg.addQuery('state', 'NOT IN', '3,4'); // Only count open tasks
agg.addAggregate('COUNT');
agg.query();
if (agg.next() && agg.getAggregate('COUNT') > 0) {
gs.addErrorMessage("All Change Tasks must be closed or cancelled before moving to the Review state.");
gs.setAbortAction(true); // Block the update
}
}
})(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
‎06-13-2025 04:52 AM
Hi @Ankur Bawiskar , thanks for your suggestion but this code is not working the change request is not moving to other states without checking the change task
any other solution.
I am thinking let's not touch the BR I created on change request table and create a new BR on change request table and try to put the post implementation test task to be closed last something like it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 03:43 AM
Hi @Harsh3842 ,
If the change tasks are active it should not allow the change request to be closed.This is the problem statement.
The business rule you have written does the required action.
The problem is that there is a flow designer in the background that is doing it?
Is my understanding right?
Thanks and Regards,
Vasudev S V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2025 04:57 AM
Hi @Vasu20, Yes your understanding is correct The BR that I have wrote it is working great but when any of the auto generated task I am cancelling or closed on the change task table I am seeing the error message because i have written gliderecord on change task table which is correct but the BR is not triggering there are still manual and one auto task which is still in open or any other state and I have not moved the change request state from implement to review where I should see the error message. Hope you are understanding my issue