Call a Workflow from an Action

In this blog post we are going to look at how to call a workflow from an action. In some case, we want to call a workflow in an action. Getting components into the workflow or updating the action when the workflow is updated becomes a new effort. In such cases, it may make sense to call a workflow in action.

I was using the HTTP REST library in a project I developed for the customer. The output obtained after many REST requests has to be listed in a dropdown component in the vRealize Automation Cloud Assembly form user interface. As you know, we use actions for external source in dropdown. In this point, I called the workflow in action like a function and extracted the REST object and returned it as an array<string>.

Let’s get to know the libraries & functions

var workflow = Server.getWorkflowWithId(workflowId);

getWorkflowWithId: Get a workflow with a given ID

If there are inputs in the workflow, we should use the code snippet below. If there is no input, don’t put anything to properties.

var inputs = new Properties();
inputs.put("input1", "value1");
inputs.put("input2", "value2");

Let’s run the workflow with inputs.

var token = workflow.execute(inputs); // return type is WorkflowToken

while(token.state === "running"){ // return type is running or finished.
    System.log("The workflow is still running... ");
    System.sleep(2000); // wait 2 secs
}

execute: Executes the workflow. Return type is WorkflowToken.

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).

All return types are properties.

var outputs = token.getOutputParameters();
if(outputs != null){
    for each (var key in outputs.keys) {
        var value = outputs.get(key);
        System.log("Key : " + key);
        System.log("Value : " + value);
    }
}

That’s all. You can successfully call a workflow form within an action in vRealize Orchestrator.

Hopefully this post has been informative for you. If you have a question, opinion or request about the article, you can contact us from the comments below or my email address. If you think this post is informative to others, be social and share it on social media! Thank you for reading !!

Leave a Reply

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