Working with vRO Properties

Properties in vRealize Orchestrator are a great way to transport complex variables between different workflows.

A property can carry several different variable types as well as be "multi-dimensional". What I mean by that is that one can define properties within properties within properties. In vRealize Automation, this is used in the payload that the event manager produces. 

Properties consist of a Key (string) and the variable that is associated with the property. For instance, the key vmName contains the name (Sting) of the VM, whereas the key vmObject could contain the VM object itself. 

Create a property

To create a property you first have to define it using (well there is more...but these are just the basics):

var vmDetail = new Properties(); 

Even if you define the output variable of a scriptable task as a property you need to initialize it with the line above.

Put content into a property

The next step would be to fill up the property with content (vm is the VMware object of type VC:VirtualMachine)
vmDetail.put("vmName",vm.name);
vmDetail.put("vmCPU",vm.cpu);
vmDetail.put("vmMem",vm.memory);

The content that is assigned to a property can be of any type: string, number, array, properties...any type of variable that vRO knows. For example lets assign an array of string to the property:

vmUsers = new Array();
vmUsers.push("Jeff");
vmUsers.push("Magret");
vmDetail.put("vmUsers",vmUsers);

Read the content of a property

To read the content of a property you can use two methods (well there is more...but again... basics). The first one is to call it by the name of the key:

System.log(   vmDetail.get(vmCPU)   );
System.log(   vmDetail.get(vmUsers)[1]   );

The second method is to walk the property, meaning to display all content:

for each (key in vmDetails.keys){
    System.log(  vmDetails.get(key)  );
}

Create properties within Properties

The ability to put properties into properties is by far the greatest feature of properties. (allVMs is an array of VC:VirtualMachine)

vmDetails = new Properties(); 
for each (vm in allVMs){
    var vmDetail = new Properties();
    vmDetail.put("vmName",vm.name);
    vmDetail.put("vmCPU",vm.cpu);
    vmDetail.put("vmMem",vm.memory);
    vmDetails.put(vm.name,vmDetail);
}