Approvers are deleted automatically by system itself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 06:21 AM
As per our business requirement , when a request is raised for application/applications access, it goes for first level approval to caller's manager. When the first level approval is done, it goes to the second level approval to the respective application's owner.
Now there are approval groups formed for each application and there are members in each approval group. The issue is that when the first level approval is done by manager, the approvers get deleted for few applications by system itself. Kindly note the whole approver group gets deleted.
Can anyone help why the system is deleting approval group(approvers) automatically by itself??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2017 01:47 AM
You may need to look into business rules on approval table. There could some bad code somewhere in Business rules/Script Includes/Workflows. Try to search through script contains 'sysapproval_approver' and script contains 'delete'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2018 08:46 AM
I think this is done directly in the User Approval Activity.
Here is the code:
/**
* Delete any approvals that we previously created but did not match during
* this creation pass
*/
_checkDroppedApprovals: function(approvalIds) {
if (!this.existingIds)
return;
var prevIds = {};
for (var id in this.existingIds)
prevIds[this.existingIds[id]] = true;
for (var i = 0; i < approvalIds.length; i++)
prevIds[approvalIds[i]] = false;
var dropIds = [];
for (var id in prevIds) {
if (prevIds[id])
dropIds.push(id);
}
if (dropIds.length > 0) {
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sys_id', dropIds);
gr.query();
while (gr.next()) {
this.approvalUtils.addApprovalHistoryGR(current, gs.getMessage("User approval for {0} deleted since it no longer matches approval rule {1}.", [gr.approver.name.toString(), activity.activity.name.toString()]));
gr.deleteRecord();
}
}
},
The sys_ids of the approvals to be deleted are gotten based on wf_activity (contains the sys_id of the activity that created the record):
_getExistingApprovals: function() {
var ids = {};
gr = new GlideRecord('sysapproval_approver');
gr.initialize();
var table = current.getRecordClassName();
// For non task related tables, add the query on document id
// For task relatd tables add the query based on sysapproval as this is what is being set while creating new approval
if( table != null && this.approvalUtils.isTask(table) ) {
// Task table
gr.addQuery('sysapproval', current.sys_id);
} else {
// Non task table
gr.addQuery('document_id', current.sys_id);
}
gr.addQuery('wf_activity', activity.activity.sys_id);
gr.addQuery('state', '!=', 'cancelled');
gr.query();
while (gr.next())
ids[gr.approver.toString()] = gr.sys_id.toString();
return ids;
},
Honestly, I am not 100% sure why this is there.
My feeling is that the system wants to make sure that only one user approval is open at the time.
This also means that any previous approval is gone for good.
It looks like a design issue to me.
If this post was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2019 05:59 AM
Finally, we found a solution.
In the loop, after an approval is given, we clear out wf_activity:
// Make sure wf_activity of the last approval is removed
// to avoid the deletion of the record
var sysid_current = current.sys_id.toString();
var grApproval = new GlideRecord('sysapproval_approver');
// Get the aproved approval in question (any where wf_activity is set)
// We do not need to identify the "last" because all should have an empty entry in wf_activity
grApproval.addEncodedQuery('state=approved^wf_activity!=NULL^sysapproval=' + sysid_current );
grApproval.query();
while (grApproval.next())
{
grApproval.setValue('wf_activity','');
grApproval.update();
}
In my opinion, this is better than modifying the Workflow activity as was suggested in
If this post was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2020 11:47 AM
Can you be more specific...are you creating a new run script in the workflow?
Thanks
-Roger