VMware Cloud Community
anoopvb
Enthusiast
Enthusiast
Jump to solution

How do workflow inputs work?

I'm trying to setup a workflow where the input is a single VM.

From there, I have a Scriptable task that gets the VMs cluster name, and vcenter fqdn.

I'd like to provide that information to a "Invoke a Powershell script" that will then reach out to a rest API (currently a static IP) and pull back some information and stick it into an array.

Using that dynamically generated Array, I'd like to prompt the user again to select one item from the array i just generated.

I figured that if I bound inputs to different scriptable tasks, that would do it but it doesn't seem to work that way.

When I run my workflow, it asks me for all the inputs at once.

Is there a way to prompt for input multiple times ?

thank you to all the help so far. Really appreciate it.

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

It should be possible to do it with data binding in the workflow presentation.

You can create a workflow with 2 input parameters, the first one of type VirtualMachine and the second one of type string. The second parameter should have a presentation property 'Predefined list of elements' bound to an action that has return type Array/string and one input of type VirtualMachine. In the property editor, edit the generated GetAction(...) expression that calls the bound action and add the first workflow parameter as an input. It should look something like

   GetAction("your.action.module.name","yourAction").call( #vm )

assuming the 'vm' is the name of your workflow input parameter.

So, every time the value of the first parameter is set, the bound action will be called. This action will parse the virtual machine input parameter, reach out to your api via powershell, and return the list of groups as array of string that will be shown as a combo box in the second workflow parameter and you'll be able to select a group from there.

The only downside would be if your group retrieval code via powershell takes too much time. In this case, the user may get a perception that the workflow presentation is stuck.

View solution in original post

6 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

How do you intend to actually launch this workflow? It is not recommended to have users launching it through the vRO client... The scenario you describe really is best addressed by prompting all info before the flow starts so you don't have to access the running workflow to answer additional questions. This is a matter of design. With that said, perhaps you have a valid reason for such an approach. If that really is the case, then you may use a "User Interaction" element in your workflow to prompt for the additional inputs. When defining those values, you specify them as Attributes, then map them to the user interaction in order to set their values. This way, the only input required when the workflow is launched is the VM, then when the user interaction element is reached, the workflow will stop and wait for a user to provide the additional required information.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
anoopvb
Enthusiast
Enthusiast
Jump to solution

Many thanks! I will give this a try today. Sorry for the newbie-ness. Still trying to get my hands around vRO.

My plan is not to start workflows from the vRO client but initiate them from vSphere Web Client. Right click a VM and choose an action.

From there, I'll get the cluster, vsphere host and then reach out to my api via powershell and get a listing of groups that the VM belongs in.

Prompt again for the group to be selected.

Currently the powershell script reaches out to a static IP for the list of groups but in the future, the powershell script could reach out to one of multiple hosts in order to fetch a list of groups.

Hence the prompt again to choose the appropriate group.

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

It should be possible to do it with data binding in the workflow presentation.

You can create a workflow with 2 input parameters, the first one of type VirtualMachine and the second one of type string. The second parameter should have a presentation property 'Predefined list of elements' bound to an action that has return type Array/string and one input of type VirtualMachine. In the property editor, edit the generated GetAction(...) expression that calls the bound action and add the first workflow parameter as an input. It should look something like

   GetAction("your.action.module.name","yourAction").call( #vm )

assuming the 'vm' is the name of your workflow input parameter.

So, every time the value of the first parameter is set, the bound action will be called. This action will parse the virtual machine input parameter, reach out to your api via powershell, and return the list of groups as array of string that will be shown as a combo box in the second workflow parameter and you'll be able to select a group from there.

The only downside would be if your group retrieval code via powershell takes too much time. In this case, the user may get a perception that the workflow presentation is stuck.

anoopvb
Enthusiast
Enthusiast
Jump to solution

Thanks so much! I'll attempt this tomorrow. Any chance this exact thing is documented some place with step by step?

i think i understand what you're saying but i'm coping with powershell module thing for vco and vco at the same time.

thanks!

0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

Hi Ilian Iliev. Thank you for that suggestion! It worked very well with a test action I created that simply returns an array of strings in javascript.

However, I'm not sure how to convert my powershell output into an array of strings. I used the "Create action from a powershell script" workflow from the Powershell 1.0.3.x plugin.

That worked really well by the way. The script is pretty straight forward.

var psScript = ''

psScript +='Connect-API ' + APIHOST + ' admin password -i -q\n';

psScript +='$grouplist = (Get-GroupInfo).name\n';

psScript +='return $grouplist\n';

return System.getModule("com.vmware.library.powershell").invokeScript( host,psScript,sessionId) ;

By default, the Action created returns a Type PowerShell:PowerRemotePSObject. I changed that to Array/String but I think there's something lost in the translation.

Do you know how I could convert that RemotePSObject to an Array/String in javascript?

I tried

var psObject = System.getModule("com.vmware.library.powershell").invokeScript( host,psScript,sessionId);

var gList = psObject.getRootObject();

return(gList);

thanks again!

0 Kudos
anoopvb
Enthusiast
Enthusiast
Jump to solution

I think i got it figured out.

var psScript = ''

psScript +='Connect-API ' + APIHOST + ' admin password -i -q\n';

psScript +='$grouplist = (Get-GroupInfo).name\n';

psScript +='return $grouplist\n';

var psObject = System.getModule("com.vmware.library.powershell").invokeScript( host,psScript,sessionId);

var grouplist = [];

var groups = psObject.getRootObject();

var isList = groups instanceof Array;

if ( isList ) {

  for ( group in groups ) {

  var item = groups[group]

  grouplist.push(item);

  }

}

return(grouplist);

I could probably just return groups in the above example to make it just a bit more efficient.

0 Kudos