How to write values in a DataTable for articles with same id

Hello the uipath community,

Help please.
I have two dt with informations about articles (id, firme, …, price).
1/ One dt (dt_multipleArticles) is the Master where i have same articles in differents shops
2/ the second dt (dt_NoDuplicateArticles), i remove all the duplicate articles in différents shops, to keep only one article.
With this second dt, i search the price of articles one by one in the mainframe that contains the right price.
After making my controls, i need to add the good price inside the first Dt (dt_multipleArticles), i need to write the good price on the last column (for the good price) but to all articles which have the same id but in differents shops.

Can anyone tell how to do that please ?

If i’m not clear, please let me know and i will do my best to be more precise.

Thank you !

Maybe @ppr you can help me out please.

@najoua.abbaci
sure we will help you. For adressing your case individually it would be helpfully if you could share some sample data and the expected output as sample. Thanks

1 Like

Sure, thank you for answering so fast !

I have the first datatable (from excel)

from this DT, first, add the column name for the last column (Q) with add data column
Then, I remove the duplicate rows with assign activity
dt_SingleArticles = (From p In dt_MultipleArticles.Select Group p By ID=p(“Article”).ToString into Group Select Group(0)).ToArray.CopyToDataTable

So, with the Dt_singleArticles, I itterate into the MainFrame to check and collect the good price.
When I have collected the good Price, I want to put the price at the column Q from the Dt_MultiplesArticles
The two DT have the same structure (same columns) but at the end, I have to put the good price, whenever it matches to the id Article(column A) from the dt_Single Article. Because, I remove the duplicate but then I need to add the price to all articles in differents shops.
Hope I am clear.

Thank you for your help @ppr

Just to be clear, in this example data rows 9 and 10 have duplicate so only one would be left after dedupe. But then when you want to update you need to update both rows

Look at the post below for more info.

It retrieves all the row index of rows which match, then you can loop through and update each one.

1 Like

@najoua.abbaci
your sample data helped to get a better understanding. I implemented a starter help on a reduced dataset and showcased 2 options:

  • nested for each /(row)
  • DataTable Join

Find xaml here:
najoua.abbaci.xaml (13.1 KB)

1 Like

Thank you for this personalized response.
However, I got an error message saying that we cannot convert a list (ofSystem.Data.DataRow) to a datatable.
Maybe I got this message because instead of the two datatable builds, I use (in) arguments (where both datatables are stored) ?
And I tryied also with two read range activities where the output is a datatable. But same error message.

And also, to simplify my process, I change the second DT : the single DT, I created a DT only with 2 columns (EAN (str var), Price (dbl var)). And let the first one, dtMulti with all the columns.
Maybe I did wrong.

Thank you again @ppr for your help

Thank you for your answer @TimK but it’s not working I have a message error.

can you please check following:

thanks @ppr

I check this and I followed the step but still the same alerte message.
I tryied something : at the end of the expression, i have added “.CopyToDataTable”.
Then no more alerte message.
But still i’m stuck. I have an error message saying that the source doesn’t contains dataRow
This is what I have done so far… I’m so confused !
PS : the first read range is the dt_Multi and the second read range is the dt_Single (in French I named it dt_PrixCtrl)

Maybe both of you can help me out here too, please.
@oddrationale
@desineediaditya
thank you

the proble is that i could not replicate the issue and was interrupted.
can you please the statement where you have added copytodatatable?

some how this is executed for an empty result that what the exception is about

I check if my two DT return empty rows but it is not even the case.

Is it what you asking for ? Picture down

@najoua.abbaci
yes one of the EAN Values returns an empty result
what was the motivation to do this?
to avoid this check the count of result and excute only copytodatatable if the couint > 0

Also it is not checking on string value base. edit like:
…Where(Function ( r ) r(“EAN”).toString.Trim.Equals(srow(“EAN”).toString.Trim)…

I’m sorry but could you please explain me how to do this in details? still have the error message.
Do I have to put a counter before the loop ?

Do I have this error message because the two files doesn’t have the same number of rows ?

Thank you for your help @ppr

Hello @ppr
I’m very confused but your first answer is PERFECT ! I’m confused coz I did wrong : two for each row insted of for each row then for each !
Hope i didn’t loose your time.
And thanks again for your precious help !

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