Script not iterating to the next row in a For Each Activity

Trying to get the script to iterate through every row. Done this by:

  1. Extracting a Data Table

  2. Assigning an Index to the first Row
    image

  3. Writing the script in the middle

  4. Ending the script with Assigning Index = Index + 1
    image

Expectation: Script iterates through every row of the Data Table

Reality: Script keeps iterating through Row 1 only.

Hey @andrea.ong ! Use “For each Row” Activity!

Hope it helps!

Hey @gabrielribas4, yes that is what I used. It’s not working.
image

Can you attach you workflow here? Thanks!

assing idx+1 inside for each loop

Done this but it doesn’t work too @Yogesh1

Sent you a message @gabrielribas4

Can you provide workflow to me also.

Hi @andrea.ong,

When you use For each row, you ideally would not need to increment index value. The for each row automatically increments and stops when the last row is handled.

However, if you still need to use a index variable, I suggest you use the default index property. Hit Ctrl+K and create new variable in that property with your required name choice. Then you can use the variable wherever you need it within the For each row activity.

The same approach can be use if you use a For each activity. Both For each and For each row activities provide you with an Index output (int).

@Yogesh1 @gabrielribas4 you’re referring to this right?
image

Remove assign activity not required in for each loop.

@Yogesh1 I don’t understand. You mean Assign Row Index = 1 at the top or Assign Row Index = RowIndex +1 at the bottom?

Hey @jeevith Ok, so I don’t need to include an Assign activity at the bottom. But rowIndex is already my variable. Why do I need to create yet another variable again please? Re: Screenshot above

Remove both Assign activity rowindex = 1, rowindex = rowindex+1

Hi @andrea.ong,

  1. The point is you don’t have to do it. An index variable already is available within a For each/For each row activities. You do not need to increment to it, it automatically does it for you. Your code can be shorter and easier to ready when you use this.

What is the rowIndex variable doing in your workflow? I don’t think you need it at all.

Just create a new variable in the properties section of the For each / For each row activity.

  1. Row index starts at 0 not 1.

  2. Have you also checked that the Extract Data from Table has successfully finished and all rows are extracted? May be it has extracted same values for all rows?

  3. CurrentRow.Item(1) will return the second column value for the given row. Is that what your If statement is using?

Get the number of rows in your extracted data table and then put the process inside a Do While loop. Do an assign in the Do While loop which reduces the number of rows and set your condition

Assign: dtRowsCount | dt.rows.count

in the Do While do an assign that says dtRowsCount | dtRowsCount - 1

And your condition will be dtRowsCount =0

Hi @jeevith @Yogesh1 , yes. The first Row is the title of the table, I only need items from Row 2 onwards.

I’ve since removed the Assign Activities from the script but now it cannot identify what row index to begin executing the script. I added an If condition before the For Each activity. Only if the condition is met, the script will run. Otherwise, to proceed to the next row in search of the key word ‘Process’
image

Now, it doesn’t even check the IF statement and runs from Row 1 by default

Hi @Yogesh1, the rowIndex variable was to indicate the specific row for the script to run. Do I put the rowIndex variable here?

image

Hi @jeevith there are too many index types:

The reason why rowIndex is there, is because i do not need to iterate through every single row. Only selected rows with the key word ‘Process’ located in Column 1.

What is the requirement here, is your for each loop working now?