VMWarevRO

Retrieve Workflow Execution Details

vRealize Orchestrator (vRO) developers is to check the results of workflows that have already executed. This can be done in the vRO 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 vRO 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.

Let’s get to know the libraries & functions

execute: Executes the workflow. Return type is WorkflowToken.

Example:

var token = workflow.execute(InputParameters); // return type is WorkflowTokenwhile(token.state === “running”){ // return type is running or  finished.
System.log(“The workflow is still running… “);
System.sleep(2000); // wait 2 secs
}

state (in WorkflowToken): Return the state of this workflow (running or finished) If you want to return information such as output, attribute and input about workflow, you can use the methods below. Apply these methods to the token object.

getInputParameters: Gets the input parameters of the workflow token (if any).

getOutputParameters: Gets the output parameters of the workflow token (if any).

getAttributes: Gets the attributes of the workflow token (if any).

To use this sample code:

  • Create a new workflow called something like “Get Workflow Execution Details”
  • Add a single Scriptable Task element to the workflow
  • 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)
  • Add the appropriate connectors and End Task
  • Paste the following code into the scriptable task
  • Validate the workflow, save, close, and execute!

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”);
}
}

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Close
Close