- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 11:20 AM
Hi,
I have a workflow issue and I'm seeking suggestions and advice from the community.
The issue concerns the approval process for change requests. As shown in the screenshot below, the process begins with 3 approvers. If any one of them rejects the request, I would like all approval statuses to change to
"No Longer Required," regardless of their current state.
Additionally, I need the Change Request record to move back to the "New" state to restart the approval process.
What options do I have for addressing this? Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 11:56 PM
Hi @Meera_P ,
Yes, You can implement this same logic using Business rules as well.
But, I'll recommend you to take assistance with someone on your instance, so that you don't break something accidentally.
I'm providing the steps to implement a business rule below:
-> Create a Business Rule to Reset Change Request State
Business Rule to Reset Change Request State:
- Navigate to System Definition > Business Rules.
- Click New to create a new business rule.
- Set the following properties:
- Name: Reset Change Request on Rejection
- Table: Change Request [change_request]
- When: Before
- Insert: False
- Update: True
- Delete: False
- Filter Conditions:
- State is not New
- Approval is rejected
Script:
(function executeRule(current, previous /*null when async*/) {
// Check if the current approval is rejected
if (current.approval == 'rejected') {
// Query all related approval records
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('sysapproval', current.sys_id);
approvalGR.query();
// Set all other approval records to "No Longer Required"
while (approvalGR.next()) {
if (approvalGR.state != 'rejected') {
approvalGR.state = 'not_required';
approvalGR.update();
}
}
// Reset the Change Request state to "New"
current.state = 'new';
current.update();
}
})(current, previous);
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 11:31 AM
Hi @Meera_P ,
Based on your requirement you can use this solution:
1. Modify Workflow to Handle Rejections
Workflow Script to Update Approval Statuses:
- Open your workflow in the Workflow Editor.
- Add a Script activity after the approval activities.
- In the Script activity, add the following code to update the approval statuses:
(function execute(current, previous /*null when async*/) {
// Check if any approval is rejected
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('sysapproval', current.sys_id);
approvalGR.addQuery('state', 'rejected');
approvalGR.query();
if (approvalGR.next()) {
// Update all approval records to "No Longer Required"
var updateApprovals = new GlideRecord('sysapproval_approver');
updateApprovals.addQuery('sysapproval', current.sys_id);
updateApprovals.addQuery('state', '!=', 'rejected');
updateApprovals.query();
while (updateApprovals.next()) {
updateApprovals.state = 'not_required';
updateApprovals.update();
}
// Update the Change Request state to "New"
current.state = 'new';
current.update();
}
})(current, previous);
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 01:21 PM
Hello @HrishabhKumar
Thank you for assisting with the code. The workflow was originally implemented by a consultant who has since left the company.
I have been learning ServiceNow for about two months now, and I don't yet have a strong grasp of the workflow to confidently make modifications. I really want to avoid making any mistakes.
Could I utilize Business Rules or another method for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 11:56 PM
Hi @Meera_P ,
Yes, You can implement this same logic using Business rules as well.
But, I'll recommend you to take assistance with someone on your instance, so that you don't break something accidentally.
I'm providing the steps to implement a business rule below:
-> Create a Business Rule to Reset Change Request State
Business Rule to Reset Change Request State:
- Navigate to System Definition > Business Rules.
- Click New to create a new business rule.
- Set the following properties:
- Name: Reset Change Request on Rejection
- Table: Change Request [change_request]
- When: Before
- Insert: False
- Update: True
- Delete: False
- Filter Conditions:
- State is not New
- Approval is rejected
Script:
(function executeRule(current, previous /*null when async*/) {
// Check if the current approval is rejected
if (current.approval == 'rejected') {
// Query all related approval records
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('sysapproval', current.sys_id);
approvalGR.query();
// Set all other approval records to "No Longer Required"
while (approvalGR.next()) {
if (approvalGR.state != 'rejected') {
approvalGR.state = 'not_required';
approvalGR.update();
}
}
// Reset the Change Request state to "New"
current.state = 'new';
current.update();
}
})(current, previous);
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2024 04:04 PM
Thank you for your advice and the code. Your detailed explanation is extremely helpful to beginners like me.