cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

For loop not working properly

CaShimiz
12-Amethyst

For loop not working properly

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;

1 ACCEPTED SOLUTION

Accepted Solutions
CaShimiz
12-Amethyst
(To:DanZ)

@dan 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.

View solution in original post

6 REPLIES 6

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 

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

 

DanZ
15-Moonstone
(To:CaShimiz)

The issue is even simpler:

 

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

 

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

CaShimiz
12-Amethyst
(To:DanZ)

@dan 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.

DanZ
15-Moonstone
(To:CaShimiz)

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

CaShimiz
12-Amethyst
(To:DanZ)

yeah, see that now. Not gonna lie, that makes me mad.

Thanks DanZ.

Top Tags