I thank you in advance for any kind of insight you can provide.
I have a data table with two columns in Studio. I have hardcoded 10 total rows of information in 2 columns. To perform an operation between the 2 pieces of data in the same Row, I used “For Each Row in Data Table” activity. Seeing unexpected result, I put a breakpoint and I found that the first iteration of the CurrentRow local variable returns the entry from the Second row of the data table! I am using the expression CurrentRow.ItemArray(0).ToString to see what entry is being processed.
Essentially, the CurrentRow local variable skips the first entry in the data table and the rest of the 9 entries are processed. I should mention that the datatable doesnot have headers.
It’s not your For Each, it’s the Read Range. You probably have headers checked, but the Excel file doesn’t have headers. So when reading, the first Excel row is used as the column names in the datatable, not the first row of data.
I guess due to check applied to Add Headers checkbox while reading the excel file. Because of this bot is considering first row as header and start’s from second row.
Uncheck the checkbox if, your data don’t have headers.
I use a output data table activity before the “For each row in data table” and I can see all the rows just fine. It is at this point that I see the discrepancy. I have done a thorough debugging, as far as I could.
Sure.
To be accurate, I have 11 rows and only 10 process inside the activity.
The screenshot is below. Yes it’s true that every thing checks out here with the data table itself. I saw that the problem is in the expression CurrentRow.ItemArray(0).ToString inside the Log Message activity. I will attach the screenshot further below.
Summary, CurrentRow local variable doesn’t seem to capture the first row???
You aren’t seeing the rows. The first row you’re seeing from Output Data Table is the HEADER row. Please take our advice and go back to your Read Range and uncheck the headers box.
Also this is why ppr suggested learning how the debug panels works, because you’d be able to see clearly that there are only 9 rows in your datatable.
Thank you!
But I don’t understand what you mean by “The first row you’re seeing form Output Data Table is the HEADER row” because I see in the immediate panel screenshot above that the data table is all data and no headers???
just type in within the immediate panel:
dt_ExcelData.Columns
and you will see, which is used for the headers.
Debugging / Working with the Debugging panels is essential and a must-have skill. If more assistance is needed refer to the debugging courses offered from the UiPath Academy
It’s not all data. Your Read Range is using the first row of data as headers. It’s naming the datatable columns from your first row of data. A header row in Excel isn’t any different from a data row, it’s all just values in cells. But the Read Range “headers” checkbox tells UiPath “use the first row to name the columns in my datatable”
When you Read Range that with headers checked, the datatable columns will be named Name, Age, and City. In a For Each Row in Data Table you’d then use CurrentRow(“Name”).ToString to get the Name value.
If you don’t have headers in your Excel file…
Paul,49,Ocala
Mary,35,Miami
…then Read Range with headers checked will name your datatable columns Paul, 49, Ocala and you’ll only have one row of data in your datatable (Mary,35,Miami).
But if you Read Range without headers checked, your columns will be auto-named Column1, Column2, Column3, and you’ll have two rows of data (Paul and Mary).