VMware Cloud Community
APJ7033
Enthusiast
Enthusiast

Action return being "converted" to object

Hi

I have a workflow with a few action in it. One of the actions returns and array of strings (link of vmnics). Then in a later scriptable task I am trying to add these vmnics to a vswitch.

In the below snippet NetworkData is my Array of String

var switchSpec = new VcHostVirtualSwitchSpec();

var loabBalPolicy = "loadbalance_srcid"

switchSpec.numPorts = 1024;

switchSpec.mtu = mtu;

switchSpec.bridge = new VcHostVirtualSwitchBondBridge();

switchSpec.bridge.nicDevice = NetworkData;

When I run the workflow I get the below error

Unable to set property 'nicDevice' on object VcHostVirtualSwitchBondBridge : org.mozilla.javascript.NativeString

nicDevice is meant to be an array of string? Do I have to iterate through NetworkData and re-create my array ?

If I output typeof(NetworkData) is state the type as object.

Tags (2)
Reply
0 Kudos
7 Replies
iiliev
VMware Employee
VMware Employee

Hi,

Which vRO version is this?

It seems the NetworkData is a string, not Array/string. Are you sure your action is properly defined to return Array/string? Could you attach your actual workflow + actions to check how the input/output mappings are defined?

Reply
0 Kudos
APJ7033
Enthusiast
Enthusiast

Ok so I found one issues with my script and something bizarre with VRO. So the issue with the script was I had an array of objects. So clearly that would never work. After fixing that up I still ran into the same issue. I finally found the fix but have no explanation for it. My VRO version is 7.4.0.8071781

So my original code looked like this:

var switchSpec = new VcHostVirtualSwitchSpec();

var loabBalPolicy = "loadbalance_srcid"

switchSpec.numPorts = 1024;

switchSpec.mtu = mtu;

switchSpec.bridge = new VcHostVirtualSwitchBondBridge();

switchSpec.bridge.nicDevice = NetworkData;

What I tried to do at first was :

var switchSpec = new VcHostVirtualSwitchSpec();

var loabBalPolicy = "loadbalance_srcid"

switchSpec.numPorts = 1024;

switchSpec.mtu = mtu;

switchSpec.bridge = new VcHostVirtualSwitchBondBridge();

var vmnics = new Array();

for(var i = 0 ; i < NetworkData.length; i++) {

vmnics.push(NetworkData[i].Device)

}

switchSpec.bridge.nicDevice =  vmnics

This kept failing with a strange error ->  Unable to set property 'nicDevice' on object VcHostVirtualSwitchBondBridge : org.mozilla.javascript.UniqueTag

So in the end I had to use the code below:

var switchSpec = new VcHostVirtualSwitchSpec();

var loabBalPolicy = "loadbalance_srcid"

switchSpec.numPorts = 1024;

switchSpec.mtu = mtu;

switchSpec.bridge = new VcHostVirtualSwitchBondBridge();

var vmnics = [];

for(var i = 0 ; i < NetworkData.length; i++) {

vmnics.push(NetworkData[i].Device)

}

switchSpec.bridge.nicDevice =  vmnics

The difference is I am now declaring my array using square braces. To the best of my knowledge both ways of declaring an array should be the same ??

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Earlier you've said that NetworkData is of type Array/string, but in these code snippets you are using it differently. What is supposed to be the value like NetworkData[i].Device if NetworkData is really an array of strings? Strings do not have a property named Device, so this expression would evaluate to undefined.

Reply
0 Kudos
APJ7033
Enthusiast
Enthusiast

So initially at first I did state NetworkData  is of type Array/string. But I was wrong, miss read my own code. The post with the working code explains that. What I still don't understand is why
var vmincs = []; works and var vmnics = new Array(); does not work.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Without knowing what are you trying to push into the array, it is hard to tell what exactly is the problem.

In general, org.mozilla.javascript.UniqueTag is used to represent 'special' object values during object serialization, like null or non-existing values.

Reply
0 Kudos
APJ7033
Enthusiast
Enthusiast

NetworkData.Device[0] = "vmnic0"

NetworkData.Device[1] = "vmnic1"

So I am just pushing a string into var vmnics = [];. The issue is when I assign that array to switchSpec.bridge.nicDevice it will only work if the array if defined as var vmnics = [];

So the below works

var vmnics = [];

switchSpec.bridge.nicDevice =  vmnics

And the below here does not work

var vmnics = new Array();

switchSpec.bridge.nicDevice =  vmnics

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

I'm totally confused Smiley Happy

The code so far showed NetworkData to be the array. The last post implies that NetworkData.Device is actually the array. Which one is what? Or are both NetworkData and Device arrays?

If the Device property is an array, then what exactly you are trying to accomplish with a line like vmnics.push(NetworkData[i].Device) ?

Reply
0 Kudos