JavaScript to Java Conversion Limitation in vRO

When vRealize Orchestrator runs scripts, the vCenter Server plug-in converts JavaScript arrays to Java arrays of a fixed size. As a result, you cannot add new values to vCenter Server data objects that take arrays as property values. You can create an object that takes an array as a property if you instantiate that object…

By

min read

When vRealize Orchestrator runs scripts, the vCenter Server plug-in converts JavaScript arrays to Java arrays of a fixed size. As a result, you cannot add new values to vCenter Server data objects that take arrays as property values. You can create an object that takes an array as a property if you instantiate that object by passing it a pre-filled array. However, after you instantiate the object, you cannot add values to the array.

For example, the following code does not work:

var spec = new VcVirtualMachineConfigSpec();
spec.deviceChange = [];
spec.deviceChange[0] = new VcVirtualDeviceConfigSpec();
System.log(spec.deviceChange[0]); //Output undefined

In the above code, vRealize Orchestrator converts the empty spec.deviceChange JavaScript array into the fixed-size Java array VirtualDeviceConfigSpec[] before it calls setDeviceChange(). When calling spec.deviceChange[0] = new VcVirtualDeviceConfigSpec(), vRealize Orchestrator calls getDeviceChange() and the array remains a fixed, empty Java array.

Workaround: Declare the array as a local variable:

var spec = new VcVirtualMachineConfigSpec();
var deviceSpec = [];
deviceSpec[0] = new VcVirtualDeviceConfigSpec();
spec.deviceChange = deviceSpec;
System.log(spec.deviceChange[0]);
/* Output
DynamicWrapper (Instance) : [VcVirtualDeviceConfigSpec]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualDeviceSpec_Wrapper] -- VALUE : (vim.vm.device.VirtualDeviceSpec) {
   dynamicType = null,
   dynamicProperty = null,
   operation = null,
   fileOperation = null,
   device = null,
   profile = null,
   backing = null
}
*/

Disclaimer This article is drawn from Release Notes of vRealize Orchestrator 8.x and is added here just for educational purposes.


Leave a Reply

Related Posts

One response to “JavaScript to Java Conversion Limitation in vRO”

  1. Teknik Informatika Avatar

    Can you provide examples of code snippets that illustrate the conversion limitations between JavaScript and Java in vRO?

%d bloggers like this: