DT expression not working

As a general introduction:
How to Update Data Column Values of a Data Table | Community Blog

For a LINQ approach, ensure the prepared dtResult which has column X on the end

(From d in dtData.AsEnumerable
Let cj = d("Column A").toString & d("Column B").toString
Let ra = d.Itemarray.Append(cj).toArray
Select r = dtresult.Rows.Add(ra)).CopyToDataTable
1 Like

Yes i had a look at the mentioned guide already.
I also tried what you suggested before, it doesn’t change the result.

The weired thing is that in an old version of the script it worked perfectly, i can’t figure out why it’s leaving some fields blank

1 Like

maybe you can share some more details on the failed rows.

However, did you tried the shared LINQ?

Thank you for your time, how should I use this command?
Actually is not working, but maybe is my fault.

Yes the concatenation string is because i need it as a key for a join dt.
In an old code the script was working perfectly

1 Like

Hey @Marzimo0404

Could you please post the query you are actually using in code, so that it will be easy to troubleshoot and suggest ?

Thanks
#nK

Yes I tried before writing here. I’m posting the script in the following answer

Ok, so i Have a DT table called “DTOrigine”, i’m adding a new column “ChiaveBilancio” and i want to fill it with a defined rule:

image

DTOrigine.columns(“ChiaveBilancio”).Expression–>“[Commodity]+[Trade_Type]+[TRANSACTION_TYPE]+[Calculation_Type]+[MarketCodeIdx2]+[CONTROPARTE_CONSUNTIVO]+[Ptf_Bilancio_Da]+[Gestore]”

1 Like

i have a total of 70K rows but just 19k are filled in

1 Like

Would suggest to focus on the LINQ approach (as more cols are involved instead of mentioned on the topic start)

“[Commodity]+[Trade_Type]+[TRANSACTION_TYPE]+[Calculation_Type]+[MarketCodeIdx2]+[CONTROPARTE_CONSUNTIVO]+[Ptf_Bilancio_Da]+[Gestore]”

(From d in dtData.AsEnumerable
Let colSet = new String(){"Commodity","Trade_Type","TRANSACTION_TYPE","Calculation_Type","MarketCodeIdx2","CONTROPARTE_CONSUNTIVO","Ptf_Bilancio_Da","Gestore"}
Let jc = String.Join(" ",colSet.Select(Function (x) d(x)))
Let ra = d.Itemarray.Append(ca).toArray
Select r = dtresult.Rows.Add(ra)).CopyToDataTable
1 Like

Hello,

i modified your code with my DT as follow:
(From d In DTOrigine.AsEnumerable
Let colSet = New String(){“Commodity”,“Trade_Type”,“TRANSACTION_TYPE”,“Calculation_Type”,“MarketCodeIdx2”,“CONTROPARTE_CONSUNTIVO”,“Ptf_Bilancio_Da”,“Gestore”}
Let jc = String.Join(" ",colSet.Select(Function (x) d(x)))
Let ra = d.Itemarray.Append(jc).toArray
Select r = dtresult.Rows.Add(ra)).CopyToDataTable

Uipath reports:
Assign: Input array is longer than the number of columns in this table.

check and ensure the correct dtresult col structure

1 Like

Ok so maybe it’s my fault, i did not explain well how my starting DT is.

the starting DT has about 40 columns, i need just the mentioned before to create a unique key in a new column (as shown in previous screen).

I guess that with your code that’s not possible since i’m taking into account just a subset of columns

Have you checked if you have cell with null value(s) where column X is empty?

E.g. the first three rows in the table below have null values:
With the expression "[Dosage]+[Drug]+[PatientID]" in Sum column you get:

image

If you modify the expression to check for null and replace it with an empty string, you will get:
Expression: "ISNULL([Dosage],'')+ISNULL([Drug],'')+ISNULL([PatientID],'')"
image

So your null safe expression should be:

"ISNULL([Commodity],'')+ISNULL([Trade_Type],'')+ISNULL([TRANSACTION_TYPE],'')+ISNULL([Calculation_Type],'')+ISNULL([MarketCodeIdx2],'')+ISNULL([CONTROPARTE_CONSUNTIVO],'')+ISNULL([Ptf_Bilancio_Da],'')+ISNULL([Gestore],'')"
1 Like

No, as it is exactly adressing it

dtData is your origin datatable

just prepare dtResult by:

  • dtResult = dtData.Clone
  • Add data Column activity and add the datacolumn (X) for the concatenated string on the end

Then run the LINQ

1 Like

This is what UiPath shows:
Assign: Exception has been thrown by the target of an invocation.

Did you mean to reply to @ppr or me? My suggestion is just to modify your Column.Expression:

DTOrigine.columns("ChiaveBilancio").Expression = "ISNULL([Commodity],'')+ISNULL([Trade_Type],'')+ISNULL([TRANSACTION_TYPE],'')+ISNULL([Calculation_Type],'')+ISNULL([MarketCodeIdx2],'')+ISNULL([CONTROPARTE_CONSUNTIVO],'')+ISNULL([Ptf_Bilancio_Da],'')+ISNULL([Gestore],'')"
1 Like

I was answering to you, ptrobot (i’m trying with your solution now).

I used your suggestion but if I use all the columns Uipath gives me that error message.
If I use just a subset (for example the first 2 columns) it works

Instead of including all columns at once, you have tried to extend the expression with one or two columns at a time to pin point the column UiPath is having issue with?

I suspect that the culprit column name is spelled wrong and doesn’t exist in the table.

1 Like

I’m checking, I’ adding one by one and let you know!

1 Like

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