Skip to main content
Kinetic Community

Majority Approval Task Process Example

This example shows how to have an approval process that allows a majority vote or consensus for the task tree to continue on.

Usage

   Sometimes you may want to send an approval request to multiple people and based on how many of the approvers vote to either approve or deny the request that determines whether the request is actually approved or denied.

    For example maybe an approval request is sent out to eleven different people and once six of the approvers choose to approve the request it is finally approved and the task tree continues on to fulfill the request. Normally we would just have a loop to send out an approval to the eleven people and wait until every approver responds (tail loop type of All) but that can unnecessarily tie up a request for a long time if ten of the approvers approve the request and the last approver takes a long time to approve or deny the request. If only a 51% majority is necessary for determining if a request is approved or denied then it would potentially be ideal to continue on with the task tree once a majority responded instead of waiting for all responses.

Example

STEP ONE - Get the approvers

Create an echo node to contain XML of every approver and then connect the echo node to a deferral node. In a real world scenario you might have a handler that grabs this from a database/remedy for you and then converts it into XML like this Functional Role Lookup

step one

But for this example we are using this hard coded value and just echoing it out:

<approvers>
<approver>approver1_id</approver>
<approver>approver2_id</approver>
<approver>approver3_id</approver>
<approver>approver4_id</approver>
<approver>approver5_id</approver>
</approvers>

 

STEP TWO - Set up the Deferral

The next step is to set up the deferral. This is the node that will make the process wait until desired level of approval has been met. The output of this node is a deferral token. This token can be used later in the process by create trigger handlers to update or complete this deferral. Create trigger nodes are how this tree will progress once the approvals have reached the appropriate level.

defer.png

In this case, we are giving the deferral node a name the customer will understand and making it visible. It can also be called something more generic and not made visible. It would depend on your process and your customer communications model.

STEP THREE - Create the Approvals

We'll now create the loop to create and process the approvals. Drag these node types onto the task builder pane: Loop Begin, Person Lookup (for whatever system you are using; this example uses the ITSM7 People form), Kinetic Request Approval Request, create trigger (shown as update defer node in the picture below), and finally loop tail. To see how to connect them up to each other take a look at the picture below.

apprLoop.png

The loop head will use the output from the 'approver list in XML' node to loop through, and the following nodes will use the the loop head's variable (which will be the approver's id) for processing.

loopHead.png

Because the approval node needs additional information (email, name) for the approval, a person lookup is necessary in this case, since we only know the approver's id. This is done by referencing the loop variable to get the approver for the instance of the loop.

lookupAppr.png

Then the approval is created. This is also a deferred node, which means it will wait for a complete trigger to come from it's workflow before this path in this tree will continue. Usually, an approval's complete trigger is generated in it's complete tree once the approver has provided a response.

Approval.png

Then, once an approval is complete, the deferred node (Waiting for the Majority of Approvals) need to evaluate the approval results provided so far to see if the approvals have reached the necessary threshold. This is done (see step three) on update of the deferred node. That means, when an approval completes, that a update trigger needs to be sent to the deferred node. This is done with a create trigger node and the deferral token result of the Waiting for the Majority of Approvals node.

UpdateDefer.png

This loop needs to be connected to the deferred node (Waiting for the Majority of Approvals) with a Create connector. The approval loop needs to start and create the approvals when the deferred node is created.

STEP FOUR - Checking the Approval Status

When any approval is completed, an update trigger is sent to the deferred node (Waiting for the Majority of Approvals), so on update (with an update connector) there is an echo node to check whether that approval was enough to finish the process and complete the deferred node (Waiting for the Majority of Approvals).

chkAppr.png

This calculation is done in an echo node with the below ruby code:

<%

  #set up variables
  index = 0.0
  approved = 0.0
  denied = 0.0

  #collect the results from the loop. 
  @results['get approval'].collect{|key,values|
    index += 1  #Count each approval in the index
    if values.has_key?('Validation Status')
      #Also count each approval or denial
      if values['Validation Status'] == "Approved" then
        approved += 1
      elsif values['Validation Status'] == "Denied" then
        denied += 1
      end
    end
  }

  #Check if more than half have approved or denied or if everyone has responded
  if (approved / index) > 0.5 then
    "yes"
  elsif (denied / index) > 0.5 then
    "yes"
  elsif (approved + denied) == index then
    "yes"
  else
    "no"    #Otherwise we aren't done
  end

%>

This node outputs "yes" if at least half the approvers have either approved or denied or if everyone has responded. Otherwise it outputs a no, indicating that the desired approval state/status hasn't been reached. Note that your approval process may be different. For example, if anyone denies, you may consider the process complete. In the case for this example, at least half of the approvers must agree or, if everyone has responded, and a majority hasn't approved, the request is denied (as you will see later).

STEP FIVE - Complete the deferred node (Waiting for the Majority of Approvals)​

From the 'have majority votes' node discussed in Step 3, is a complete connector with the following evaluation. 

chkConnector.png

This means the following nodes will only be executed once this statement evaluates to true, i.e. once the calculations in the 'have majority votes?' node result in a yes value. Once this is the case, any approvals still pending should be expired, and the deferred node (Waiting for the Majority of Approvals) should be completed (with a Complete trigger) so that the tree can progress.

completeDeferred.png

STEP SIX - Continue the Tree and get the Approval Results

The deferred node (Waiting for the Majority of Approvals) has now been completed, so the tree will now follow the complete connector to move on down the tree. But the first thing you need before you can really progress appropriately is to know what the approval result was, so the first node after the deferred node is an echo that processes the approvals to determine the results.

apprResults.png

The contents of the 'Approval Results' are the following code to calculate the approval result:

<%=
  
  #set up variables
  index = 0.0
  approved = 0.0
  denied = 0.0

  #collect the approval results from the loop
  @results['get approval'].collect{|key,values|
    index += 1  #Count each approval in the index
    #Also count each approval or denial
    if values.has_key?('Validation Status')
      if values['Validation Status'] == "Approved" then
        approved += 1
      elsif values['Validation Status'] == "Denied" then
        denied += 1
      end
    end
  }

  if (approved / index) > 0.5 then  
    "Approved! #{approved}/#{index}"  #If more than half approved, this request was approved
  elsif (denied / index) > 0.5 then
    "Denied! #{denied}/#{index}"      #If more than half denied, this request was denied
  elsif (approved + denied) == index then
    "Denied! #{denied}/#{index}"      #If everyone responded and a majority didn't approve, the request is denied.
  end

%>

Now that there is an approval result, connectors off the 'Approval Results' node can then refer to this result and take the correct actions.

 

Download Example

An example Service Item, described in this article, is attached. The attached example does not include a catalog and will need to be moved into a catalog. Also, the attached example will not work without an approval template and message template. You will want to hook that up to your approval item (or download a sample approval item from another solution and set this example to use that template).
 
MajorityApprov_2014_03_13__113754885.zip