Trick Question: Assign Dynamic ID's to a Column

Hi Folks,

I have Datatable with several columns, for keeping this example simple I am keeping two columns (ID,CostCentre) both of which are stored in a datatable

Cost Centre Values Sample: 901200,832100,459212,…

I have 750 such rows.

I want to assign a unique number value in the ‘ID’ column w.r.t each CostCentre.

As 750 rows already exist, I want the ID’s to start with 751 and can be in the range 750-999.

Please help as to how I can approach this ?

Ther are several options

One of them:

set it to true

give a seed:
DataColumn.AutoIncrementSeed Property (System.Data) | Microsoft Learn

when an existing datatable is to post labeling we can do it with above and a merge datatable trick.

Alternates:

  • For each Update
  • LINQ

@ppr , can we do it using the UiPath friendly way. Like read a datatable and then using assign activities?

Any help is appreciated :slight_smile:

Yes as mentioned:

Assign Offset Variable: myOffset| Int32 = 750
For each row Activtiy | row in YourDataTable
(configure index output - idx

  • Assign Activity: row(ColName) = (idx + myOffset)

Hey @shikharno.7 ,

After you have read the excel, you can retrieve the last value of the ‘id’ column.
Let’s say for this case it got ‘750’ as the value. You can then store this value in a variable and then use it in a loop to increment it, which you can update in the excel.

The process may look something like this:

assign idValue=

(From row In dt
 Let a= row("id").ToString
 Select a).Last

So this will give you the last value of the ‘id’ column.

Then you can use for each loop to increment the id and add to the excel

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