when anyone rejected group approval then don't set as no longer required it should be set as request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
1.Requirement : When a change request is created and sent for group approval (e.g., AXA Group, HSBC Group, Axis Group), if any group member rejects the request, the status should not be set to 'No Longer Required'. Instead, it should be updated to 'Requested for Other Group Approval'. After this, when a member from another group approves the request, the status of other members within the same group should automatically change to 'No Longer Required'. However, when I approve the request as a member of the same group, the status of other group members is not updating to 'No Longer Required'—it still shows as 'Requested'. we are facing this kind of issue. if anyone know please let us know. fix my issues. below are given details of this requirement.
i did it through script for this on group approval table.
code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @sangitaakum
have you been considering to achieve this via a flow?
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @sangitaakum as suggested by GlideFather, the expected behaviour could be achieved via Flow.
But for the the issue described, it looks like you are simply “fighting the approval engine". You’re updating approvals broadly from a change-level script, and a few coding issues combined with the platform’s automatic re-evaluation process are reversing your changes.
- From the looks of it, you loop over change_request and then try to “fix” child approvals. That’s gonna be brittle and slow. I would suggest to Trigger on sysapproval_group/sysapproval_approver instead, where the event actually happens.
- In script #1 there’s a logic bug: inside while (gr1.next()) you later do while (gr1.next()) again (likely meant gr2.next()), so the inner loop never runs.
- You update sysapproval_approver with a query on approval_for (wrong field). The join from approver → group approval is sysapproval (and to the task is document_id).
- You assign gr2.state = gr1.approval (mismatched fields/enums).
- Statuses “reverting to requested” = OOTB approval flows/business rules re-evaluating when the Change is touched. If you don’t cancel/close the pending approvals properly (at the group level and approver level), they can be regenerated or re-opened.
Based on this, I would suggest you to try these small fixes: To find the approver rows under a group approval:
appr.addQuery('sysapproval', <sysapproval_group.sys_id>);
(not approval_for.)Don’t set gr2.state = gr1.approval; map states properly (approved ↔ approved, requested ↔ requested, not_required ↔ not_required).
Never loop while (gr1.next()) inside another while (gr1.next()). Use the right variable.
Avoid scanning all change_request. Work from the current approval record that changed.
If this pointed you in the right direction, hit Helpful to spread the good vibes.
✅ If it cracked the case for you, mark it Correct so the next person doesn’t have to reinvent the wheel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Requirement:
When a Change Request (CR) is sent for group approval:
If any group rejects the request, the approval status for other groups should not be changed to "No Longer Required". Instead, their status should remain as "Requested".
If more than 60% of the groups approve the request, then the overall Change Request approval status should be updated to "Approved".Currently, when 60% of the groups approved the request, the system incorrectly changes the status of the remaining groups from "No Longer Required" to "Requested".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The requirements were clear enough, however seems like you didn't fully like the answer provided....
Anyway, I'll try to see if I can provide some kind of "direct solution" that doesn't require refactoring what you've already described.
Let go with this suggestion then - and please note, that because we don’t know your exact approval setup, flows, or customizations, this approach may not behave as you expect and could introduce side-effects. Test thoroughly in a sub-prod instance!!
Assumptions are that You are using group approvals (table sysapproval_group) tied to Change Request as parent. And that choice values are
OOTB: approval (group) = requested/approved/rejected/not_required; state (approver) mirrors that.
Create BR A - Group approval finalize (same group only)
Table: sysapproval_group
When: After update
Order: 3000 (ensure it runs after OOTB change/approval BRs)
Condition (Script or simple):
current.parent.table == 'change_request' && current.approval.changes()
(function executeRule(current /*, previous*/) {
// Guardrails
if (gs.isActionAborted()) return;
if (!current || !current.parent || current.parent.table != 'change_request') return;
if (!current.approval || !current.approval.changes()) return;
try {
// A) One member in a group approved → close peers in the same group (requested → not_required)
if (current.approval.changesTo('approved')) {
var peers = new GlideRecord('sysapproval_group');
peers.addQuery('parent', current.parent);
peers.addQuery('assignment_group', current.assignment_group);
peers.addQuery('sys_id', '!=', current.sys_id);
peers.addQuery('approval', 'requested');
peers.query();
while (peers.next()) {
if (peers.approval == 'requested') {
peers.setWorkflow(false);
peers.setValue('approval', 'not_required');
peers.update();
// Cascade to approvers under that group approval
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', peers.sys_id);
appr.addQuery('state', 'requested');
appr.query();
while (appr.next()) {
appr.setWorkflow(false);
appr.setValue('state', 'not_required');
appr.update();
}
}
}
}
// B) If a group rejected → do nothing to other groups (they stay requested).
// Intentionally no cross-group changes on reject.
} catch (e) {
gs.warn('BR-A error on sysapproval_group: ' + e);
}
})(current);
Then we move along to BR B - Auto-approve Change at 60% and freeze the rest
Table: sysapproval_group
When: After update
Order: 3050 (after BR-A)
Condition:
current.parent.table == 'change_request' && current.approval.changes()
(function executeRule(current /*, previous*/) {
if (gs.isActionAborted()) return;
if (!current || !current.parent || current.parent.table != 'change_request') return;
if (!current.approval || !current.approval.changes()) return;
try {
// Count distinct groups for this Change
var totalGroups = 0;
var allGA = new GlideAggregate('sysapproval_group');
allGA.addQuery('parent', current.parent);
allGA.groupBy('assignment_group');
allGA.query();
while (allGA.next()) totalGroups++;
if (totalGroups === 0) return;
// Count distinct groups that have at least one record approved
var approvedGroups = 0;
var okGA = new GlideAggregate('sysapproval_group');
okGA.addQuery('parent', current.parent);
okGA.addQuery('approval', 'approved');
okGA.groupBy('assignment_group');
okGA.query();
while (okGA.next()) approvedGroups++;
var pct = (approvedGroups / totalGroups) * 100;
if (pct >= 60) {
// 1) Approve the Change (use setWorkflow(false) to avoid churning approvals)
var chg = current.parent.getRefRecord();
if (chg.isValidRecord()) {
if (String(chg.getValue('approval')) !== 'approved') {
chg.setWorkflow(false);
chg.setValue('approval', 'approved');
chg.update();
}
}
// 2) Freeze remaining non-finalized group approvals as NOT REQUIRED
var pend = new GlideRecord('sysapproval_group');
pend.addQuery('parent', current.parent);
pend.addEncodedQuery('approval!=approved^approval!=not_required');
pend.query();
while (pend.next()) {
pend.setWorkflow(false);
pend.setValue('approval', 'not_required');
pend.update();
// Cascade to approvers
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', pend.sys_id);
appr.addEncodedQuery('state!=approved^state!=not_required');
appr.query();
while (appr.next()) {
appr.setWorkflow(false);
appr.setValue('state', 'not_required');
appr.update();
}
}
}
} catch (e) {
gs.warn('BR-B error on sysapproval_group: ' + e);
}
})(current);
Because your exact approval generation mechanism (Flow Designer vs. BRs vs. custom) and Change workflows are unknown, this solution may need tweaks.
I hope that this might help you with achieving your desired outcome.
Or at least give you an indication on how you could approach it.
If this pointed you in the right direction, hit Helpful to spread the good vibes.
✅ If it cracked the case for you, mark it Correct so the next person doesn’t have to reinvent the wheel.