I've created a flow that builds a table (8 columns x 20 rows) from web data. I'm now trying to build a loop that looks at the first cell of each row to evaluate the contents.
However, I cannot seem to find a structured reference for the loop that doesn't generate a syntax error.
If I try, "For each %CurrentItem% in %DataFromWebPage%" I get 20 iterations, which is what I want. However, within the loop, I don't seem to be able to use the %CurrentItem% variable as part of a structured reference. %DataFromWebPage[0][0]% gives me the first row, first column. But, I can't find a way to embed a reference to %CurrentItem% to bring my looping construct into the loop. What's the right syntax for embedding a variable reference within a variable reference? I want something like %DataFromWebPage[%CurrentItem%][0] and I get why that doesn't work, but I can't find an escape character that allows me to do the embedded declaration ... any advice?
Sorry if this is a dumb question ...
Solved! Go to Solution.
Hello there and thank you for your question!
Iterating through a datatable variable with a 'For each' loop - as you have already done so - is indeed a correct first step; this provides you with a datarow variable in each iteration, stored within the %CurrentItem% variable.
Within the iteration, you can reference the individual elements of the datarow by using indices, via the notation %CurrentItem[0]% - this would get you for instance the first cell of the respective row, as indices are zero-based in PAD variables. Similarly, you could use %CurrentItem[1]%, %CurrentItem[2]% and so on.
For your reference, another approach you could use is a nested 'Loop':
Loop from 0 to 19, incrementing by 1 and storing in %RowIndex%
Loop from 0 to 7, incrementing by 1 and storing in %ColumnIndex%
%CurrentVar%= %DataFromWebPage[RowIndex][ColumnIndex]%
End
End
Of course, this approach would iterate through all the elements of all the rows one by one, so maybe it's not optimal for what you are trying to achieve. But it should give you an idea of the proper use of indices for datatable variables as well.
Last but not least, when you are referencing columns, in case you have column headers available in your variable, you can also use the notation %CurrentItem['<ColumnHeader>']% or %DataFromWebPage[RowIndex]['<ColumnHeader>']%. This is handy when you want to easily remember which column you are referring to.
Please let us know if the above explain things for you. Thank you!
Hello there and thank you for your question!
Iterating through a datatable variable with a 'For each' loop - as you have already done so - is indeed a correct first step; this provides you with a datarow variable in each iteration, stored within the %CurrentItem% variable.
Within the iteration, you can reference the individual elements of the datarow by using indices, via the notation %CurrentItem[0]% - this would get you for instance the first cell of the respective row, as indices are zero-based in PAD variables. Similarly, you could use %CurrentItem[1]%, %CurrentItem[2]% and so on.
For your reference, another approach you could use is a nested 'Loop':
Loop from 0 to 19, incrementing by 1 and storing in %RowIndex%
Loop from 0 to 7, incrementing by 1 and storing in %ColumnIndex%
%CurrentVar%= %DataFromWebPage[RowIndex][ColumnIndex]%
End
End
Of course, this approach would iterate through all the elements of all the rows one by one, so maybe it's not optimal for what you are trying to achieve. But it should give you an idea of the proper use of indices for datatable variables as well.
Last but not least, when you are referencing columns, in case you have column headers available in your variable, you can also use the notation %CurrentItem['<ColumnHeader>']% or %DataFromWebPage[RowIndex]['<ColumnHeader>']%. This is handy when you want to easily remember which column you are referring to.
Please let us know if the above explain things for you. Thank you!
Brilliant! I didn't realize that the %CurrentItem% was, itself, both the iterative construct and a data element. Thank you, kind sir.