Create a Column that has the index numbers

Hey UiPath group think! I feel like I am brain farting here.

I have a data table and I want to add a column that will contain the row index number. What will be the best way of going about this?

Thanks!

-James

@jamills

Use Add Data Column activity to add Column.

1 Like

@jamills after using the ‘Add Data Column’ activity pointed out by @lakshman, you should use a ‘For Each Row’ activity and put the following in an assign activity (assuming datatype is integer, if datatype is string, just append .ToString at the end on the right side of the assign activity): Assign row.item("YourNewColumnName") = YourDataTableVariable.IndexOf(row)

3 Likes

Hello James,

Probably the best way to do this is to not add it if it’s not necessary and you’re just using it as you’re going through the data. The ReFramework has the index value TransactionNumber that you can use to reference the row in the TransactionData.

There’s also the For Each Row’s index: https://docs.uipath.com/activities/docs/for-each-row#section-output

If you absolutely need it in with the data, the Add Data Column should do as @lakshman stated. However, you would have to set the datatype to Int32 and check the AutoIncrement option I believe and it should automatically populate with the numbers you need.

2 Likes

Hey everyone! I really appreciate the quick responses! I’m going to go through and try out your responses.

1 Like

To anyone that ends up reading this in the future. Dave’s solution worked. If you have trouble the right side of the assign, you can always create another assign that counts each row: rowIndex (this needs to be an int) = rowIndex + 1. And his assign will read as: Assign row.item(“YourNewColumnName”) = rowIndex

1 Like

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