Approval Condition script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 10:39 AM
Hi Team ,
In Approval User activity -> Number of Owner Approvals triggering based on catalog variable selection ..
If anyone approves , system should wait for other owner response and once responded , RITM state as "approved"
Unitl all other owner respond , system should not goes to " no longer required "
below conditon script is not working (
var approvePercent = 50;
if((counts.approved/counts.total)*100 >= approvePercent){
answer = 'approved';
}
if((counts.rejected/counts.total)*100 > = 100 {
answer = 'rejected';
Example - if 4 owner approvals are in queue ,
if one person approved and 3 persons are rejected .. system should takes as approved in RITM state choice
only all owners rejected , then system should takes as rejected in RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 02:09 PM
The variable you are using represent the number of groups approving, rejecting, etc., not the number of individual approvers. You need to use the variables for each group - e.g. groups[group_id].approved, groups[group_id].rejected, groups[group_id].total. Even if there is only 1 group in the approval, you need to use these variables and iterate through the groups list. See below for an example based on your code.
var approvePercent = 50;
var totalapproved = 0;
var totalrejected = 0;
var totaltotal = 0;
// loop through all groups and aggregate the counts
for (var id in groups) {
var group = groups[id];
totalapproved += group.approved;
totalrejected += group.rejected;
totaltotal = group.total;
}
if ((totalapproved / totaltotal) * 100 >= approvePercent) {
answer = 'approved';
}
if (((totalrejected / totaltotal) * 100) >= 100) {
answer = 'rejected';
}
I think that your rules need to be updated a little bit however since it is unclear what should happen if you don't get a majority of approvals but don't hit 100% rejections (for instance 2 out of 5 approvals, 3 out of 5 rejections).
If this helped resolve your issue, please mark as helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 11:22 PM
Based on CI selection , approval triggers to CI owners
Any Idea
approvals which is in requested state , should be wait for other approvals result? once all are responded , then should decided whether RITM is approved/ rejected
if anyone approved -> it should be approved
Right now , if two approved , rest of things moved to - no longer required state

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2022 05:39 AM
Hi,
Based on the your example below is the logic you can apply.
/*Example -
if 4 owner approvals are in queue ,
--> if one person approved and 3 persons are rejected .. system should takes as approved in RITM state choice
--> only all owners rejected , then system should takes as rejected in RITM
*/
//Script
var answer;
var totalUser = counts.total;
var approveduser = counts.approved;
var rejectedUser = counts.rejected;
var requestedUsers = counts.requested;
if(rejectedUser == totalUser){
//all owners rejected , then system should takes as rejected
answer = 'rejected';
} else if(approveduser) { //anyone approves the request
//waiting for other users answer
if(requestedUsers == 0){
//all users has been either approve or reject the request.
answer = 'approved';
}
}
Mark this as Helpful/Correct if this helps you in anyways.
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 06:28 AM
Hey @Sourabh26 This piece of code worked.
Could you advise how to include manual/adhoc approval in above code?
This is not considering any manual approval