Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
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;
Solved! Go to Solution.
@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.
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().
The issue is even simpler:
let tablelenght = sites.rows.lenght; --> should be called length
Otherwise you can also use "sites.getRowCount()".
@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.
If you look closely you see that you've wrote: "let tablelenght = sites.rows.lenght" not length.
yeah, see that now. Not gonna lie, that makes me mad.
Thanks DanZ.