- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 08:32 AM
When I check the "On hold" checkbox in a change request it places the change on hold. When I un-check this "On hold" checkbox and save, it removes the hold then resets the approvals. What script controls the behavior of resetting the approvals?
I need to override this behavior so that the existing approvals are not affected.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 02:33 PM
If you need to override this behavior and keep the existing approvals intact, you can write a script that prevents the system from resetting the approvals when the "On hold" checkbox is unchecked. To do this, you can create a Before Business Rule on the Change Request table, and add the following script:
(function executeRule(current, previous /*null when async*/) {
// Check if the "On hold" checkbox is being unchecked
if (current.on_hold.changes() && !current.on_hold) {
// Get the current state of the approvals
var approvals = current.approvals.getDisplayValue();
// Set the "On hold" checkbox back to checked
current.on_hold = true;
// Update the change request record
current.update();
// Restore the state of the approvals
current.approvals = approvals;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 09:48 AM
@Ian Mildon, I do not see a "Change Request: On hold" OOTB business rule in a fresh instance either.
@Chaitanya Redd1, thanks for recommending using a business rule.
For the life of me, I can't identify the BR affecting the approvals. However, creating a new BR with a sufficiently low order and using setWorkflow(false) worked successfully.
Ultimately, I created the following business rule to provide the desired behavior:
When to run: before
Order: 8
State is: Authorize
On hold changes to false
Action: set on hold to false
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 09:50 AM
I'm accepting the answer from @Chaitanya Redd1 as the solution since a new BR provided my desired behavior.
The below issue is kinda-sorta similar and gave me the idea to use setWorkflow(false):
How to stop running the business rules when we ru... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 06:58 AM
Additionally, the workflow may also impact the approval flow. When working on this I also noticed that some additional modifications need to be made to address issues with Emergency change requests. Specifically, Emergency change requests (Emergency type, Emergency change model) will update all remaining approvals to "No Longer Required" under the following conditions:
1. After the first approval is issued
2. After placing a change on-hold, then taking it off-hold
My organization needed to prevent this since we desired to capture all approvals/votes on a change. The following may also be needed:
1. Business Rules > SNC - Notify Flow (Approval): preempt this business rule from running specifically for Emergency change requests. We preempted this Business rule from running for both Normal & Emergency change models, e.g.,
(function executeRule(current, previous /*null when async*/ ) {
if (current.source_table.toString() === 'change_request' && current.sysapproval.chg_model.getDisplayValue() === "Normal")
"do nothing";
else if (current.source_table.toString() === 'change_request' && current.sysapproval.chg_model.getDisplayValue() === "Emergency")
"do nothing";
else
sn_fd.FlowAPI.notifyApprovalAction(current);
})(current, previous);
2. The "Change Request - Emergency" workflow will need to be modified as well to prevent "No Longer Required" approvals. You may also simply inactivate the Workflow.
3. Revise the Change Approval Policies > "Emergency Change Policy"