Forum Discussion

pkudrys's avatar
pkudrys
Contributor
3 months ago
Solved

(JavaScript) Unable to get value(s) from TableVariable passed to a function

Hi folks, 

I want to pass a Table Variable to my custom function and obtain value from defined row number and column name. 

At first, I tried to follow the sample code from TC User Guide: 
https://support.smartbear.com/testcomplete/docs/reference/program-objects/tablevariable/index.html

But the sample fails at Iterator.Reset(); line with "cannot read property" error...

But the problem seems to be at previous line MyIterator = MyVar.Iterator; which does not return Iterator object, although the MyVar successfully loads Table variable "steps".

I also renamed the Iterator variable to MyIterator, just to make sure it does not interfere with Iterator property, but no luck either.

Does anyone have an idea what's wrong? Is there something missing, the sample code is obsolete or I found a bug? Thank you in advance.

BTW, is there a way to get the value from table variable via column name/row index? 

  • MyVar is an Object, that just contains ColumnCount and nothing else. It should also contain TableVariable Object Properties. This is the reason why Reset fails, as there's no Iterator.

    You need to check this,

    to ensure it's returning the correct object type.

6 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You're assigning MyIterator = MyVar.Iterator. What is the type and the value of MyVar?

  • MyVar contains Table variable, defined in Keyword test. If you check the second screenshot, you can see it shows ColumnCount=1 so the MyVar appears to by correctly filled with Table object. 

    The problem is, that MyVar.Iterator returns "nothing". But according to the user guide, Iterator property should return Iterator object, which provides a scripting interface to rows of the array. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    MyVar is an Object, that just contains ColumnCount and nothing else. It should also contain TableVariable Object Properties. This is the reason why Reset fails, as there's no Iterator.

    You need to check this,

    to ensure it's returning the correct object type.

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        It's good to see someone using the Watch List and trying to diagnose the issue 🤖 

        To diagnose an issue, try to work backwards, from where you think the issue is occurring (line 43), and you will have more of a chance in solving the problem.