VMware Cloud Community
goldeneyez
Contributor
Contributor

array.splice in vRO | vRO version 7.2.0.4629841

I encounter an issue when I am running the following code: array.splice

var XPath_query = "xpath:vimHost/about/instanceUuid[ . = '52980cec-f750-41d3-af39-a8f7d7ae8d60' ] and name[ . = 'Something']";

System.log(XPath_query);

var allClusterComputeResources_Array = VcSdkConnection_Array[0].getAllClusterComputeResources([],XPath_query);

var allClusterComputeResources = allClusterComputeResources_Array[0]

var z=0

System.log("z value is: " + z);

System.log("array length before splice: " + allClusterComputeResources.datastore.length);

eval((allClusterComputeResources.datastore).splice(z,1));

System.log("array length after splice: " + allClusterComputeResources.datastore.length);

when I execute the following command:

[2018-11-19 15:09:25.733] [I] z value is: 0

[2018-11-19 15:09:25.734] [I] array length before splice: 7

[2018-11-19 15:09:25.736] [I] array length after splice: 7

the content of allClusterComputeResources.datastore is as following:

[2018-11-19 15:09:25.729] [I] DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-2389>'VMTemplate',DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-586>'vmds1205',DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-585>'vmds1204',DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-587>'vmds1206',DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-582>'vmds1202',DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-581>'vmds1201',DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-584>'vmds1203'

so , for unknown reason I am not able to omit and remove an element from array by executing the command:

eval((allClusterComputeResources.datastore).splice(z,1));

or

allClusterComputeResources.datastore).splice(z,1);

thanks in advanced.

0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee

You cannot modify the internal arrays within vRO plug-in objects this way.

One option it to introduce a temporary array variable. For example, if you replace the last 3 lines of your code with the following:

var datastores = allClusterComputeResources.datastore; // new temporary array variable

System.log("array length before splice: " + datastores.length);

datastores.splice(z,1);

System.log("array length after splice: " + datastores.length);

you'll see that it the first element of datastores array will be removed.

0 Kudos