change group Approvals via script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 08:04 AM
Hello Experts!
I have a little struggle with Group approvals for changes. I have a workflow, but in this particular case, I do not want to use it. Hence I add for this change via a script multiple approval groups. But as soon as someone approves from these groups (sys_approval table already) the rest of the changes are not set to not needed anymore.
Does someone have an idea why this happens?
The code i use is :
var val = dev.u_mapr_microservices.split(",").length > 0 ? true : false;
var groupApprovals = ['f8947dfe0f9f76000643f68ce1050e00','e04c13c76f2f5600526b7357ea3ee4d2'];
if(val){
groupApprovals.push('4aec8ea76f0b5100685246916e3ee4d5');
log("GroupApprovals array is +1 " + groupApprovals);
generatePerGroup(groupApprovals, current.sys_id);
}
else{
log("GroupApprovals is 2 groups " + groupApprovals);
generatePerGroup(groupApprovals);
}
function generateApproval(group){
var approval = new GlideRecord('sysapproval_group');
approval.initialize();
approval.active = true;
approval.assignment_group = group;
approval.parent = current.sys_id;
approval.approval = 'requested';
approval.priority = current.priority;
approval.state = 'requested';
approval.insert();
log("Ading Approval for CHANGE " + current.number + " app.number);
}
function generatePerGroup(groups){
for(var i in groups){
log("Generate approval for " + groups[i]);
generateApproval(groups[i]);
}
}
So, is there something I am doing wrong ? The type is Anyone to approve in the sys_approvals table.
Thanks in advance!!!
Cheers,
Joro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 04:20 PM
Hi Georgi,
I think a BR on the Group Approval table, sets the remainder of approvals of a particular group to 'No Longer Required'(not_required) once one of the approvals for the group is either approved or rejected. You can check 'sys approval_group' table for the BR. I do not remember the name of the BR, but it should be an easy find.
Darshak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2017 11:54 AM
Hi,
I added a business rule, that handles this type of tickets. As soon as any approval is received per group (approved/rejected) the rest of the approvals are marked as not needed. It uses the group approval record itself - easier than iterating through all approval records.
Cheers,
Joro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2017 01:50 PM
Hi Georgi,
I still wonder, why you had to create a new BR to mark the approvals as not needed. Can you check for 'SNC - Moot user approvals for group' BR on sysapproval_group table? Do you have it? Is it inactive?
Best,
Darshak
Edit: Why does generatePerGroup has dynamic number of arguments? I see generatePerGroup(groupApprovals, current.sys_id) and generatePerGroup(groupApprovals) function calls.