- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 10:28 PM
Hello,
I created a business rule to query the approval table for requests within my custom table.
I want the BR to put all other requested approvers except the one that approved into a "No longer Required" status.
Here is my business rule:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 10:47 PM - edited 05-13-2025 10:49 PM
Hi @BenjaminY
Try the below script.
(function executeRule(current, previous /*null when async*/ ) {
var target_rec_id = current.document_id;
var target_rec_table = current.source_table;
// Ensure the record is from your custom table
if (target_rec_table == 'x_g_dh5_ccht_ccht_task') {
var targetGR = new GlideRecord(target_rec_table);
targetGR.get(target_rec_id);
targetGR.record_status = 'Cancelled'; //update record status field to cancelled
targetGR.update();
// 2. Set all other approvers to "not_required"
var otherApprovers = new GlideRecord('sysapproval_approver');
otherApprovers.addQuery('document_id', target_rec_id);
otherApprovers.addQuery('sys_id', '!=', current.sys_id); // Exclude current
otherApprovers.addEncodedQuery('stateINrequested,approved'); // Only update active approvers
otherApprovers.query();
while (otherApprovers.next()) {
otherApprovers.setValue('state', 'not_required');
otherApprovers.setWorkflow(false);
otherApprovers.update();
}
}
})(current, previous);
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 11:18 PM
isn't this happening OOTB?
If you are using Group approval and your setting is "Any one to approve", then if 1 person approves then all other will be set as "No longer required" by system only
what's your use-case here? share some more details and screenshots.
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
05-23-2025 09:02 AM
the system does not recognize "Cancelled" as an option. Even adding If record_state == Cancelled condition to flow did not work for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 08:47 AM - edited 05-14-2025 08:51 AM
The BR was created so when a request on my custom table is put into "Cancelled" status it will be dynamic as the Ask Approval OOB function within flow designer. Currently in my flow designer I have if == "Cancelled" the action is not being triggers due to the Ask approval only functioning from Approval or Reject.
Here is the working Business Rule:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 08:49 AM
That's what I mentioned that this should happen OOTB if you have "Anyone approved" applied for your approval.
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