vRA 7 Create a Folder Selection Dropdown

Another quick post, I needed to create a dropdown box that would give a user the ability to select which vCenter folder a newly provisioned VM should be placed in. The custom property we need to set here is VMware.Virtualcenter.Folder, if you don’t want to give your users access to choose which folder to place a new VM in, but you want to ensure all of their VMs go in a specific folder you can set this property in a number of places.

Anyway for this example I want users to be offered a dropdown box on the request form, that will list all of the child folders in a folder called “Management Servers”.

In order to do this I need to create a vRO action and then a Property Definition to enable this.

vRO Action

The code for the vRO action is as follows:

var parentFolder = “Management Servers”;

var vmFolders = VcPlugin.getAllVmFolders();

var arrFolders = [];

 

for(var i in vmFolders){

if (vmFolders[i].parent.name == parentFolder)

{

arrFolders.push(vmFolders[i].name);

}}

return arrFolders;

 

You will need to specify a return type of Array/String

If you want to test the code copy it to a new workflow and sciptable task and change the return arrFolders; line to System.log (arrFolders); and ensure you are getting back the folders you expect to see

Property Definition

Setup you Property Definition as follows:

You need to select your newly created action from vRO:

Attach the property definition to the Blueprint:

Now you have a dropdown to select the vCenter Folder:

Hope someone finds this useful

Facebooktwittergoogle_pluslinkedinby feather

Leave a Reply

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