slideshow 6 slideshow 4 slideshow 8 slideshow 1 slideshow 2 slideshow 3 slideshow 5 slideshow 7

vRealize Orchestrator workflow with approvals and timeout

This workflow demonstrates an approval process whre two approvers will have the opportunity to approve or deny a request and when both approvers don't respond within the time limit then the workflow will continue as if it was approved. So this will actively give the two approvers a time window to deny a request after which it is automatically approved. Is designed to use n AD group for approver 1 and another AD group for approver 2.

Download the workflow file here

This is the original request:

vCenter Orchestrator workflow request

This is a screenshot of the result:

vCenter Orchestrator Workflow with approval and timeout

This is the code of getting the current time to check if it is within business hours:

var time = new Date ;
var hour = time.getHours();
System.log(hour);

(In this example it is always compared with the time at the Orchestrator Server since we can't have access to the local time of where you run the client to execute the workflow.)

This is the code of setting the timeout for the approval:

timerDate = new Date(); 
timerDate.setTime( timerDate.getTime() + (approvalTimeoutInMinutes*60000) ); 
timeout1=timerDate;

This the code for checking the Business Day. There is an array with regular Business Days (1,2,3,4,5) and one with dates that are non Business Days (Jan 1)

//check if today is a business day 
var businessDay = false;
var nonBusinessDay = false;
var date = new Date;
var dayofweek = date.getDay();
var hour = date.getHours();
var dayOfMonth = date.getDate();
var month = date.getMonth();
var year = date.getYear();
//loop through the array of non Business Days to check whether today is one
var arrayLength =nonBusinessDays.length;
for (var i = 0; i < arrayLength; i++) {
    var checkDayOfMonth = nonBusinessDays[i].getDate();
    var checkMonth = nonBusinessDays[i].getMonth();
    var checkYear = nonBusinessDays[i].getYear();
    //System.log(nonBusinessDays[i]);
    //System.log(checkDayOfMonth+"-"+checkMonth+"-"+checkYear);
    //System.log(dayOfMonth+"-"+month+"-"+year);
    //System.log(dayOfMonth+"-"+month+"-"+year);
   if ((dayOfMonth==checkDayOfMonth) && (month==checkMonth) && (year==checkYear))
   {
    System.log("Today is "+date+" which is a nonBusinessDay");
    nonBusinessDay = true;
   }
}
//Only continue if it is not a non Business Day
if (!nonBusinessDay)
{
var arrayLength =businessDays.length;
for (var i = 0; i < arrayLength; i++) {
  if (dayofweek==businessDays[i])
  {
    businessDay = true;
    //System.log("Today is day "+dayofweek+" which is a Business Day (" + businessDays[i] +")");
    }
    else
    {
//    System.log("Today is day "+dayofweek+" which is not a Business Day (" + businessDays[i] +")");
    }
}
//Now that we know if it is a Business Day we will look at the time
if (businessDay)
{
System.log(hour);
if ((hour >= businessHourStart) && (hour < businessHourEnd))
{
businessDay = true;
}
else
{
businessDay = false;
}
}
}

Follow us on LinkedIn