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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Code inspector warning with "for each"

iguerra
14-Alexandrite

Code inspector warning with "for each"

I have this warning when I use "for each" statement

iguerra_0-1601392092177.png

An old thread related to TW 8.3 was telling it will be fixed with future release, I have TW 8.5.6 but warning is still present.

Can this be fixed ?

 

5 REPLIES 5
slangley
23-Emerald II
(To:iguerra)

Hi @iguerra.

 

Can you provide more info on what you're trying to do?  There may be an alternative approach.

 

Otherwise, we recommend posting your suggestion on the ThingWorx Ideas page.  This will allow other community members to vote for it, which will increase it's chances of being adopted for a future release.

 

Regards.

 

--Sharon

 

 

iguerra
14-Alexandrite
(To:slangley)

Hello @slangley 

Just a loop, iterating infotable data (the sample I wrote is just to show the warn message, no code in the loop)

For-each works very well, it has no problems, code inspector  just shows the warning on the syntax that is instead correct. IMHO code inspector shows a wrong warning.

 

I know I can use a classic for loop with an index, but for-each is easier/beautiful/clean because doesn't need use row_length, an index variable, and also an object variable to point easily to the row data (instead of always write infot.rows[index]).

 

bbeuckSIG
15-Moonstone
(To:iguerra)

I am afraid the warning is legit. I am running Thingworx 8.4.4 on Chrome 85.0.4183.121. For each produces a warning in design time and is completely ignored in runtime. No exception or anything, just ignored.

 

Here I get 1 log entry (yes, the DataTable does have records):

var entries = me.GetDataTableEntries({maxItems: 9999999});
logger.debug("Start for each with entries: " + entries.length);
for each (var entry in entries) {
    logger.debug("entry: " + entry);
}

 

Here I get 1+n entries:

var entries = me.GetDataTableEntries({maxItems: 9999999});
logger.debug("Start for each with entries: " + entries.length);
for (var i=0; i<entries.length; ++i) {
    var entry = entries[i];    
    logger.debug("entry: " + entry);
}

 

iguerra
14-Alexandrite
(To:bbeuckSIG)

With for-each I need to use infotable.rows, like

for each (var entry in entries.rows) {

differently it will loop just one time with the whole (and single) infotable object.

instead specifiying .rows it will loop all records (it's an array).

try ...

 

 

 

bbeuckSIG
15-Moonstone
(To:iguerra)

Absolutely makes sense. Tested immediately and had success. Thank you.

Top Tags