DEV Community

Mayank Goyal
Mayank Goyal

Posted on • Originally published at cloudblogger.co.in on

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 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
Enter fullscreen mode Exit fullscreen mode

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
}
*/
Enter fullscreen mode Exit fullscreen mode

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


Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay