VMware Cloud Community
JFCooleCC
Contributor
Contributor

Listing properties of any object/scriptable class?

This feels like a dumb question and I am certain I am missing something obvious.

I want to be able enumerate properties for any object I pass through.  Sometimes it's quick and easy to do this within a scriptable task.

The problem is, the way I would do this in JS simply doesn't work in vCO.

Say I have an input parameter of type VirtualMachine assigned as 'inputVM'.

I'd do something like this in standard JS:

for(var x in inputVM) {

if(inputVM.hasOwnProperty(x)) {

   System.log("The property name is: " + x + ", and the value is: " + inputVM[x] )

}

}

But, running that exact bit of code in my task just returns this as an error:

TypeError: Invalid iterator value (Workflow:List Properties / Scriptable task (item1)#10208)

If I run a typeof on the inputVM, it says its a function, which is a type of Object anyway.

Can someone help with a quick and simple solution?  Is it because the inputVM is a scriptable class in vCO that the normal way doesn't work?

0 Kudos
1 Reply
cdecanini_
VMware Employee
VMware Employee

Yes, this is because this is not a pure javascript object but a java object exposed as an object in javascript.

I am not a Java person but I recall being told that if the java object class was private then JS (Rhino exposing the jab object as JS), would not be able to introspect the object.

If Ilian is around today he can certainly answer in better terms.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos