Remove approval and reflect in workflow

hartr
Giga Contributor

I'm looking for a way to manually remove or cancel a group approval that has been added by workflow. I can set the approval status to "No Longer Required" but that doesn't get communicated to the workflow so it waits forever for that record to either be approved or rejected. Can anyone advise how I can achieve this ?
Thanks

12 REPLIES 12

sherman_1206
Tera Contributor

You need a path from your approval box on your workflow for when the approval is set to "no longer required".

Notice how on a workflow approval box there are two paths, approval and rejected. These are based on the approval records result. If you right click on the approval box you can add another condition and make it so if "no longer required" you go another route (or the same route as approved or rejected for that matter.)


sherman_1206
Tera Contributor

One more comment: If you double click on "approved" or "rejected" you can see what condition must be sufficed to take this path.

In case of approved you have following:



activity.result == 'approved' || activity.result == 'skipped'


If approval is marked approved or skipped we take the "approved" path.

If you wanted to take approved path when approval was marked "no longer required" you could add to the above condition code:



activity.result == 'approved' || activity.result == 'skipped' || activity.result == 'not_required'


However, if you are modifying the approval records state field via business rule or some other script and not a user action you may need a business rule to "bump" the workflow to re-evaluate its conditions to move forward. I can explain this if needed.


hartr
Giga Contributor

I was thinking along the same lines and already tried what you suggested (have a look at the comprehensive w/f on demo). If you set the status to no longer required then the workflow doesn't know you've done it. Would appreciate your thoughts on the business rule you are thinking of, and whether you think the activity definition itself needs to be modified ?


Can you clarify on when and how would the manual removal take place? Is this based on a business rule?

Since I think I understand what you want to do I will make some assumptions. You can always correct me later. 🙂

So basically if I have a change_request record which has a workflow running on it and it has generated a group approval for group X. Lets assume group X has 5 members in it. Also lets assume that for some situation (per your thread here) 2 of the 5 approvals are no longer required. I could do a script (business rule or something) that would remove those 2 approvals.

As you mentioned:



//construct gliderecord for query
var a = new GlideRecord("sysapproval_approver");
//grab change sys_id or whatever record approval is for
//from somewhere
var id = change_request.sys_id;
//filter some query criteria
a.addQuery("approval_for", id );
a.addQuery("state", "requested");
a.addQuery("approver", user1.sys_id);
a.addQuery("approver", user2.sys_id);
a.query();
//iterate over to remove these approvals
while(a.next() ){
a.state = "not_required";
a.update();
}


At this point you have done half the work.

What is the problem? Well, in a normal situation when you interact with a change record or approval for a change record there are out-of-box business rules which trigger the workflow to re-evaluate its conditions and potentially move forward. In your case of scripting this does not happen.

What can we do to make this workflow run? Easy, lets continue with the script a bit. (This continues after end of above while I did not want to copy above for length purposes.)



var w = new Workflow();
var c = new GlideRecord("change_request");
//remember here variable id = change_request.sys_id
if ( c.get( id ) )
w.runFlows(c, 'update');


Simply huh? All we had to do was construct a workflow object and have it bump/nudge if you will the change_request records workflows.

The above can be generalized by replacing the var c = new GlideRecord("change_request"); with "task" and then you can query for any parent task record and bump its workflows.

A good example I have found where I use this is when I have a sc_req_item record workflow which generates a change_request. I want the sc_req_item to close out when change closes out but the sc_req_item workflow never gets bumped unless you have an after/async business rule on change_request that will bump the in my example here current.parent (which is the sc_req_item).

Help? Make sense?

If not ask away we can get this working I am sure, just takes a bit to put all the pieces together then you will have the "ah hah" moment.

Cheers!