Skip to main content
14-Alexandrite
February 24, 2022
Solved

For loop not working properly

  • February 24, 2022
  • 2 replies
  • 2497 views

Hi everyone,

 

I'm trying to do a simple for loop to get some fields from getimplementingthingswithdata into another property to be used in a collection.

When I execute the following code without the For loop, it works fine. But I can't seem to get the for loop working. 

Can anyone help me figure out what is wrong with my code?

 

the var result is declared earlier in the code.

 

// result: INFOTABLE dataShape: "RootEntityList"

let sites = ThingTemplates["BALL.Sites_ThingTemplate"].GetImplementingThingsWithData();

let tablelenght = sites.rows.lenght;

for (let x = 0; x <= tablelenght; x++) {

// SitesCollec_datashape entry object

        let newEntry = {

            Site: sites.rows[x].name, // STRING [Primary Key]

            Location: sites.rows[x].description, // STRING

            Img: sites.rows[x].ImagemPlanta, // IMAGELINK

            ICL: sites.rows[x].ICL, // NUMBER {"minimumValue":0,"maximumValue":100}

            EficienciaDQO: sites.rows[x].EficienciaDQO, // NUMBER {"minimumValue":0,"maximumValue":100}

            EficienciaFluoreto: sites.rows[x].EficienciaFluoreto, // NUMBER {"minimumValue":0,"maximumValue":100}

            Indicador4: undefined // NUMBER

        };

result.AddRow(newEntry);

}

me.implemSites = result;

Best answer by CaShimiz

@unknown if you notice, my code is written lenght. Not sure if you misread or was pointing something different. 

In any case, I changed to getRowCount() and got it working. 

Weirdly it seems my rows.length doesn't work.

2 replies

12-Amethyst
February 24, 2022

Hello CaShimiz,

 

After reading your code, I believe you should use var instead of let to declare variables. The globle variable and local variable may not be able to pass the value.

In addition, you may build an infotable with the appropriate datashape and enter an object as a row, which you can then assign to the appropriate property in the infotable.

 

Thanks and Regards,

Rushikesh Shrimal 

CaShimiz14-AlexandriteAuthor
14-Alexandrite
February 25, 2022

I tried with var as well and it didn't change much. The only way I got it to work was using RowCount().

 

15-Moonstone
February 25, 2022

The issue is even simpler:

 

let tablelenght = sites.rows.lenght;  --> should be called length 🙂

 

Otherwise you can also use "sites.getRowCount()".

CaShimiz14-AlexandriteAuthorAnswer
14-Alexandrite
February 25, 2022

@unknown if you notice, my code is written lenght. Not sure if you misread or was pointing something different. 

In any case, I changed to getRowCount() and got it working. 

Weirdly it seems my rows.length doesn't work.

15-Moonstone
February 25, 2022

If you look closely you see that you've wrote: "let tablelenght = sites.rows.lenght" not length. 🙂