VMware Cloud Community
GarTomlon
Enthusiast
Enthusiast
Jump to solution

Populate an array of vc:virtualmachines from a list box

I would like to create a predefined list of VMs that allows me to select multiple one (as in a listbox) and have the selected vms be a member of an array.  I have looked but not having any luck.  Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, predefined list of element (or predefined answers) will accomplish that.

Just make sure that the input parameter you are adding predefined list of elements property to is of type Array/VC:VirtualMachine, not of type a singular VC:VirtualMachine

View solution in original post

8 Replies
Uridium454
Enthusiast
Enthusiast
Jump to solution

Are you attempting to achieve this in vRO alone, or pushing to a vRA XaaS form?

I am doing this exact thing with vRA form by using an action to populate the list of VM names.  You can pull these values using the "predefined answers" from the presentation tab.

GarTomlon
Enthusiast
Enthusiast
Jump to solution

For right now, this will reside in vRO.  It 'could' find its way into vRA (as you said as XAAS).  I am looking now at the predefined answers.

Reply
0 Kudos
Uridium454
Enthusiast
Enthusiast
Jump to solution

I believe you will be stuck in vRO with what will appear to be an array box with possible input values in a drop down.  Once ported to vRA with an input type of array/string, you will get the check box option as the expected input will be of an array type.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Usually, this is done by adding 'Predefined list of elements' presentation property to your array input field and binding the property value to a scripting action call that returns the list of VMs to choose from.

'Predefined answers' will also work.

GarTomlon
Enthusiast
Enthusiast
Jump to solution

When I say listbox, I really want a checkbox.  Ultimately, what I would like is a predefined list of 10 VMs presented in the list.  I would like to be able to select any number of those VMs and have the selected VMs be part of the array that will get modified in the workflow.  Will the predefined list of elements or predefined answers accomplish that?  I have created drop down list where you select a singluar item from the list.  But here, I need to be able to select multiple.  If so, what would I do differently than when I created the drop down list (with predefined list of elements created from action)?

I have really gotten great help here and I really do appreciate all the assistance and pointers.

Tom

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, predefined list of element (or predefined answers) will accomplish that.

Just make sure that the input parameter you are adding predefined list of elements property to is of type Array/VC:VirtualMachine, not of type a singular VC:VirtualMachine

GarTomlon
Enthusiast
Enthusiast
Jump to solution

OK, I have created the list box using Predefined Elements.  It is not very clean. but it is working.  I will probable circle back later to clean that up possible.  Where I am having problems (I think), is how to handle the selected VMs.  I have a scriptable task  that I intend for it to create the array from the selected VMs.  I am just not sure how.  Below is a snippet of what I have at this point for this outcome.  I am not sure if it is necessary to provide everything (dont want to overload).  If you need additional info for my request, please let me know.  I am pretty sure that the script is completely wrong - I used a similar one to feed an output attribute from a drop-down box - not a list box.

1.) I have created a Config-Element that is array type that contains the list of all possible VMs to select from.  Attribute is vmsList

1.)vmList Config Element.JPG

2.) I created an action to 'GET' those Vms from the ConfigElement (getVmsList)

2.) Create Action getVmsList.JPG

3.)  Created a workflow with the following attributes:

3.) TestArray2-WF-Attrib.JPG

4.)  Added the following input

4.) WF Input.JPG

5.)  Added scriptable task with the following input parameters

5.) Selected Task - Inputs.JPG

6.)  Added an output parameter for the array that I would think that the selected/chosen VMs would be used in.

6.) Scriptable Task Output.JPG

7.)  The visual bindings for the scriptable task

7.) Scriptable Task - VisualBindings.JPG

8.)  Code for the scriptable task

8.) Scriptable Task - Scripting.JPG

9.)  Presentation config

9.) Presentation config.JPG

I am assuming that what I have as far as the script is for a dropdown box with a single selection - not a listbox building an array.  I really do appreciate the help.

Tom

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

vMachines input parameter contains the selected VMs, so on step 8 you can set the value of chosenVMs attribute by simply assigning it:

if (vMachines == null || vMachines.length == 0) throw "No VMs are selected!";

chosenVMs = vMachines;