Search code examples
javascriptvbscriptqtphp-uft

Accessing the properties of an Object that resides in another Object


I am using UFT and VBS and I am getting an object from a JavaScript command that returns other objects, but I am unable to access these objects properties.

In detail:

  1. I run in UFT a command that returns all the data from a SlickGrid table. The command is grid.getData(); and returns an object.
  2. This object is set to object variable objListArray and the hierarchy is:
objListArray (Object)
      |
      |---0 (Object)
      |        |
      |        |---Property1 : Value
      |        |---Property2 : Value
      |        |---Propertyx : Value
      |        
      |---1 (Object)
      |        |
      |        |---Property1 : Value
      |        |---Property2 : Value
      |        |---Propertyx : Value
      |
      |---2 (Object)
      |        |
      |        |---Property1 : Value
      |        |---Property2 : Value
      |        |---Propertyx : Value
      |
      |---n (Object)
               |
               |---Property1 : Value
               |---Property2 : Value
               |---Propertyx : Value

No matter what I tried I cannot access the properties of the objects. Any ideas how I can access these properties? I am limited to VBS as this is for a UFT script.

So far I tried without success:

objListArray(0).Property1   '--> Generic error

For Each x in objListArray  '--> Object does not support that

various other combinations that return a generic error.


Solution

  • I realized that the object is of type JScriptTypeInfo

    In order to access it I can use the bellow:

    objListArray.[0].Property1
    

    Now, to iterate through the Object you can do it like that:

    For i = 0 To objListArray.Length-1
        x =  eval("objListArray.[" & index & "].[Account Number]")
        'Do anything you want with x
    Next