when im updating in record in sysapproval group table it is asking to set global variable answer.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2024 12:25 AM
//Approve based on percentage from each group var approvePercent = 50; var approveCount = 0; for(var id in groups){ var group = groups[id]; if((group.approved/group.total)*100 >= approvePercent){ //Mark the group approval record 'Approved' var groupApproval = new GlideRecord('sysapproval_group'); groupApproval.get(id); groupApproval.approval = 'approved'; groupApproval.update(); approveCount++; } if((group.rejected/group.total)*100 > (100 - approvePercent)){ answer = 'rejected'; break; } } //Ensure all groups have approved if(approveCount == counts.total){ answer = 'approved'; }
the above script is not working when we approveit, it is asking to set answer = approved when we update the record in sysapproveal group table to approved using script.
bbut the will make all the approvals approved and returns the change to next state.
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2024 12:48 AM
Check if this helps:
// Approve based on percentage from each group
var approveThreshold = 50;
var approvedGroupsCount = 0;
var totalGroups = Object.keys(groups).length;
for (var groupId in groups) {
var group = groups[groupId];
var approvedPercentage = (group.approved / group.total) * 100;
var rejectedPercentage = (group.rejected / group.total) * 100;
// Check if group meets the approval threshold
if (approvedPercentage >= approveThreshold) {
var groupApproval = new GlideRecord('sysapproval_group');
if (groupApproval.get(groupId)) {
groupApproval.approval = 'approved';
groupApproval.update();
approvedGroupsCount++;
}
} else if (rejectedPercentage > (100 - approveThreshold)) {
answer = 'rejected';
break;
}
}
// Ensure all groups have approved
if (approvedGroupsCount == totalGroups) {
answer = 'approved';
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2024 01:57 AM
it is not working setting the sysapproval_group.approver value to 'sn_comm_management.CommunicationManageme'
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2024 01:55 AM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2024 03:09 AM
declare answer variable on the top script like as below.
var answer = []
var answer = '';
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.
Thanks
dgarad
Thanks
dgarad