How to script the addition of approval 'escalations' while keeping the original approver?

tombialkowski
Giga Expert

Hi all,

We currently have a script that allows for approval escalations which flows as follows:

        - Item is requested and manager approval is required.

        - If 2 days goes by and the manager has not approved, escalate to the manager's manager.

        - 2 days later, repeat this process and escalate to the manager's manager's manager.

The script checks to see if the next manager in the chain is a VIP:

        - If the next manager is VIP, stop execution of the approval escalation workflow.

        - If the next manager is NOT a VIP, continue to escalate up the chain every 2 days.

Now functionally the script is taking the old manager out of the approval record, replacing it with the manager that the approval was escalated to and calling .update(). Which means that if the original approving manager suddenly grants approval 2.5 days in, after it has escalated, the approval is discarded because that particular manager is no longer listed as an approver.

I experimented with changing .update() to .insert(), which works in the sense that both managers are listed as a potential approver. The problem is that the Request Item stands still until both approvals are received (Original Manager and any Escalated Managers).

We want to fix this so that any manager in the escalation chain can approve, and if any one person does approve, the remaining approvals are no longer required. Anyone have any thoughts or suggestions that might put me on the correct path?

1 ACCEPTED SOLUTION

tombialkowski
Giga Expert

I was reading up on workflows and remembered that workflows terminate the moment End is reached, so I came up with an alternate approach that should work very nicely, feels much cleaner, can be expanded upon and helps keep the process closer to being 'out of the box'.



First I created a new subflow called GetManagerApproval:


find_real_file.png



I then added the following variable to GetManagerApproval's subflow properties, which is assigned a yes/no value in the two run scripts (approved/rejected) just prior termination:


find_real_file.png



And then created an example workflow for the Service Request Item:


find_real_file.png


Double-clicking the GetManagerApproval activity, I set the 'Map to return value' to match the variable previously created (The If activity tests this variable for a yes/no, returned from the subflow, and acts accordingly):


find_real_file.png



It works perfectly whether I stop it at 1st, 2nd or 3rd level. And I figured there's a problem if you are having to escalate 3 or more times for approval. But if it should be needed I can simply add another layer or two into the subflow:)



Let me know if you have any questions.


View solution in original post

29 REPLIES 29

tombialkowski
Giga Expert

I was reading up on workflows and remembered that workflows terminate the moment End is reached, so I came up with an alternate approach that should work very nicely, feels much cleaner, can be expanded upon and helps keep the process closer to being 'out of the box'.



First I created a new subflow called GetManagerApproval:


find_real_file.png



I then added the following variable to GetManagerApproval's subflow properties, which is assigned a yes/no value in the two run scripts (approved/rejected) just prior termination:


find_real_file.png



And then created an example workflow for the Service Request Item:


find_real_file.png


Double-clicking the GetManagerApproval activity, I set the 'Map to return value' to match the variable previously created (The If activity tests this variable for a yes/no, returned from the subflow, and acts accordingly):


find_real_file.png



It works perfectly whether I stop it at 1st, 2nd or 3rd level. And I figured there's a problem if you are having to escalate 3 or more times for approval. But if it should be needed I can simply add another layer or two into the subflow:)



Let me know if you have any questions.


Can you please help, what script need to write on Set Workflow Approved and If Approved.



I am doing > Run Script>Set Workflow Approved> current.subflow='true'   and in If Approved> if(current.subflow=='true'.)



Is it right.


I've made some changes since I last posted, but Set Workflow Approved simply sets the workflow variable subflow_approved = 'approved'



find_real_file.png



find_real_file.png



Setting to rejected does pretty much the same:


find_real_file.png



If Approved then checks this workflow variable and acts accordingly by returning 'yes' or 'no':


find_real_file.png



I went this route because I am still learning how to manipulate built in variables such as activity.result and not having much success (Likely because I haven't had time to slow down and study up on it).



Hope it helps.


Thanks for your help Its working fine. But one thing when I am rejecting the approval it is till creating catalog task. I checked the workflow it is giving "Yes" output even   if we reject and creates the task.



Please help.


I am using this, its still going to No,even I approver.



answer=ifScript();


function ifScript()


{


if(workflow.scratchpad.subflow_approved=='approved')


  {


    return 'yes';


  }


else if (workflow.scratchpad.subflow_approved=='rejected')


  {


return 'no';


  }


}