A common task among vCenter Orchestrator (vCO) developers is to check the results of workflows that have already executed. This can be done in the vCO Client by clicking the plus sign next to the Workflow you are checking on, but this isn't always the most desirable method. For instance, you may have a vCO Policy/Task setup to check the executions of other workflows at a recurring interval. The following code can help guide you to gathering the desired information.

To use this sample code:

  1. Create a new workflow called something like "Get Workflow Execution Details"
  2. Add a single Scriptable Task element to the workflow
  3. Add a new Input Parameter named "requestFlow" of type "workflow" to the scriptable task. (Be sure this is an Input Parameter so that when you execute this workflow, you will be prompted to select a workflow to get details from)
  4. Add the appropriate connectors and End Task
  5. Paste the following code into the scriptable task
  6. Validate the workflow, save, close, and execute!

Code Sample:

var tokens = requestFlow.executions; // Each execution is a "workflowToken" object
for each (token in tokens){

  if (token.isStillValid){
    System.log("");
    System.log("==== Checking token ====");
    System.log("Start Date: "+token.startDate);

    if(token.endDate != null){
      System.log("End Date: "+token.endDate);
    }

    System.log("Business State: "+token.businessState); // Indicates the business state as defined by the workflow dev in each of the elements of the workflow (not always specified)

    System.log("State: "+token.state); // Indicates the system state of this workflow
    /* State values are likely to be one of the following:
    waiting
    failed
    completed
    canceled
    running
    */
    System.log("");
    System.log("==== Token Inputs ====");
    var inputParams = token.getInputParameters();
    if (inputParams != null){
      for each (key in inputParams.keys){
        var value = inputParams.get(key);
        System.log(key + ": " + value + " ("+System.getObjectType(value)+")");
      }
    }
    System.log("");
    System.log("==== Token Attributes ====");
    var attributes = token.getAttributes();
    if(attributes != null){
      for each (key in attributes.keys){
        var value = attributes.get(key);
        System.log(key + ": " + value + " ("+System.getObjectType(value)+")");
      }
    }
    System.log("");
    System.log("==== Token Outputs ====");
    var outputParams = token.getOutputParameters();
    if (outputParams != null){
      for each (key in outputParams.keys){
        var value = outputParams.get(key);
        System.log(key + ": " + value + " ("+System.getObjectType(value)+")");
      }
    }
  }else{
    System.log("WARNING - INVALID TOKEN ENCOUNTERED");
  }

Note: The properties/methods used above may not be available via the SOAP API.

For your convenience, .workflow file attached (Right Click and Save Link As...) file icon workflow get workflow execution details.workflow