How to assign indexof(row) to Row in For Each Loop

Hi

For each Row in Data table,i need to assign the index of that row that has been captured back to the row in for each Row, so as to perform some other arithmetic operations.Please advise.

1 Like

HI @amr07

Have a counter variable which starts from 0.
In the For Each Row activity, have the counter variable increment by 1. So in each iteration, it will contain the index of the row :slight_smile:

Int32 Counter = 0
For Each Row - Item of DataTable
Begin

    //Your Data table row processing 

    Counter = Counter + 1

End

Hope it helps

Thanks for the reply.I need the index assigned back to the row.so that when certain conditions meet i would like to tweak accordingly.
Here since the counter is an interger how can this be assigned to row which is of type system.data.datarow?please advise

Hi @amr07

You can do it like this. Check the sample workflow…
Here First I read a set of data from an excel file. Then I add a new column to the datatable to hold the index. Then in the For Each Row activity, I assign the row value to the new column.

I guess this is what you need :slight_smile:

AddRowIndex.xaml (7.3 KB)

Let know whether this works out for you.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.