- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 11:55 AM
Hello Experts,
Please help me to resolve this.
Change was rejected and there are still existing approvals that were not cancelled. These are individual (manual) approvals that were added it didn't cancel them.
Thanks,
Nani.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:24 PM
This business rule is doing a whole lot more than your original question so I am unsure how to help with this. What is the table on this business rule and what is the condition?
Basically you need to put a run script in your workflow that is connected to the Rejected condition on your approval. This way if the approval is rejected it will run a script to cancel the manual approvals before the workflow ends. You can leverage some of the code in your business rule in the run script. Though I see you are querying just where document_id matches the current.sys_id. With approvals for task based tables, the sysapproval value on the sysapproval_approver table is also populated with the task sys_id. You may want to change the query like I did below:
//reset all approvals
var groupApprovalIDs= [];
var currApprovals = new GlideRecord('sysapproval_approver');
var qc = currApprovals.addQuery('document_id',current.sys_id);
qc.addOrCondition('sysapproval',current.sys_id);
currApprovals.query();
while(currApprovals.next()){
if(currApprovals.group != ''){
groupApprovalIDs.push(currApprovals.group.sys_id.toString());
}
currApprovals.state = 'cancelled';
currApprovals.comments = 'Change reset to draft. Auto-cancelling all approval requests.';
currApprovals.update();
}
//reset all group approval records found...
var groupApprovals = new GlideRecord('sysapproval_group');
groupApprovals.addQuery('sys_id', 'IN', groupApprovalIDs);
groupApprovals.query();
while(groupApprovals.next()){
groupApprovals.approval = 'cancelled';
groupApprovals.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:40 PM
OK this case your business rule never runs because rejection of an approval doesn't change the state of the change_request to draft. I am not sure what you are trying to do with this business rule honestly but maybe it works for some other use case. Since approvals are being handled via the workflow the best place to deal with rejections is the workflow so please follow my suggestion of adding a Run Script activity that connects to the Rejected condition of your approval activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 12:45 PM
Ok. Thankyou. Could you help me with the script i need to use in the run script activity. I'm not good at scripting.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 01:13 PM
This is not tested but something like the following should work:
//reset all manual group approval records. this will automatically mark individual approvals associated to this group as rejected.
var groupApprovals = new GlideRecord('sysapproval_group');
groupApprovals.addQuery('parent', current.sys_id);
groupApprovals.addQuery('approval', 'requested');
groupApprovals.query();
while (groupApprovals.next()) {
groupApprovals.approval = 'rejected';
groupApprovals.update();
}
//reset all manual user approval records.
var userApprovals = new GlideRecord('sysapproval_approver');
var qc = userApprovals.addQuery('document_id', current.sys_id);
qc.addOrCondition('sysapproval', current.sys_id);
userApprovals.addQuery('state', 'requested');
userApprovals.query();
while (userApprovals.next()) {
userApprovals.state = 'not_required';
userApprovals.update();
}
Please mark any of the answers helpful or solved so others can benefit from the answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 01:49 AM
Hi Michael,
how to get the last rejected comment and add as current comment for all cancelled approval?