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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Simple For Loop for Infotable Iteration

No ratings

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.

Comments

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

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

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

Version history
Last update:
‎Mar 22, 2017 11:01 AM
Updated by:
Labels (3)