Skip to main content
14-Alexandrite
March 22, 2017

Simple For Loop for Infotable Iteration

  • March 22, 2017
  • 4 replies
  • 11836 views

This is using the simplest structure to do a look through an infotable.  It's simple but it avoids having to use row indexes and cleans up the code for readability as well.

 

//Assume incoming Infotable parameter names "thingList"

for each (row in thingList.rows) {

     // Now each row is already assigned to the row variable in the loop

     var thingName = row.name;

}

 

You can also nest these loops (just use a different variable from "row").  Also important to note to not add or remove row entries of the Infotable inside the loop.  In this case you may end up skipping or repeating rows in the loop since the indexes will be changed.

4 replies

19-Tanzanite
April 13, 2017

Thanks Tudor,

I think it is useful to know that the same loop is available under the Snippets section in the Composer side, under the "Infotable for loop" name.

BR,

Vladimir

14-Alexandrite
April 13, 2017

Thanks for the feedback Vladimir Rosu.

Adam wrote this code and it differs from the snippet in that it does not use a row index (for  x=0 ... x < tableLength ...).  It's just a little improvement on the snippet to make the code more readable.  I agree -- functionally it is the same

22-Sapphire I
April 13, 2017

to add:

From snippets there is also

// infotable datashape iteration

var dataShapeFields = yourInfotableHere.dataShape.fields;

for (var fieldName in dataShapeFields) {

  //logger.warn('field name is ' + dataShapeFields[fieldName].name);

  //logger.warn('field basetype is ' + dataShapeFields[fieldName].baseType);

}

and there is

Looping through a JSON nested structure

AdamR14-AlexandriteAuthor
14-Alexandrite
May 18, 2017