VMware Cloud Community
dkor
Contributor
Contributor

Is it possible to call a Workflow from an Action

I'd like to use an external service to provide inputs for some elements in a custom form.
I've created an action for it, but appropriate code is already available in a workflow.

Is it possible to call the workflow directly from the action and avoid duplicating the same code in two places.

Thanks

Reply
0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee

Yes, it is possible. Check the documentation in vRO API Explorer for Workflow scripting object, and its method execute()

​Let me know if you need further info.

eoinbyrne
Expert
Expert

Yes, you can like this

var wfTokens= [];

// create the properties map to hold all the inputs

var wfInputs = new Properties();

// add all the inputs to the map in pairs

wfInputs.put(inputName1, inputValue1);

var wfToken = wf.execute(wfInputs);

wfTokens.push(wfToken);

System.getModule("com.vmware.library.vc.basic").waitForCompletionForBatchWorkflow(wfTokens);

// examine the token to see the outcome of the workflow execution

System.log("Name, Start Date, State, End Date");

for each(var wfTok in wfTokens)

{

System.log(wfTok.name + "," + wfTok.startDate + "," + wfTok.state + "," + wfTok.endDate);

}

// check API Explorer in the client to see what else you can get from the token

Note that if by a custom form you really mean vRA XaaS Advanced Service forms, then you'd be better off to just duplicate the code into an action. Starting a workflow will make the form a lot slower that it would be if you used an action.

-Eoin