Previously used Invoke Code to convert a date format. Need help with alternate code

Currently on UiPath 2020.10 which has a bug with Invoke Code.
I have code which currently uses the invoke code activity to convert the date format from the "Effective Date” column from "MM/dd/yyyy” to “yyyy-MM-dd 00:mm:ss”.
can anyone suggest an alternative to invoke code or a for each loop? The table is large.

Invoke Code activity
Edit argument - Name=CleanTable , Direction=in/out , Value=“table”
Language =VBNet

CleanTable.AsEnumerable().ToList().ForEach(Sub(row)row(“Effective Date”)=DateTime.ParseExact(row(“Effective Date”).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd 00:mm:ss”))

thank you!

Hi,

Do you have any exception? Or do you mean getting wrong output?

Regards,

Hi @jsilvestre ,

Could you check with the below component if you are able to get the output as required :

In such scenario I used to use SetField method:
CleanTable.AsEnumerable().ToList().ForEach(Sub(row) row.SetField("Effective Date", DateTime.ParseExact(row("Effective Date").ToString,"MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd 00:mm:ss"))

Cheers

When I try to use the mentioned code I get the below error.
I’ve used this in the past but with the new packages a bug was introduced.

image

Any alternative methods?

Is setfield an activity?

I don’t see the component in packages I’m able to access.

Hi,

Can you try to downgrade UiPath.System.Activities package to 20.10.x or lower if you use 21.10 or above? Because InvokeCode activity in System.Activities package 21.10 doesn’t support Studio 20.10 or lower. Please see the following known issues.

Regards,

No, it is a method of DataRow class.
The code itself is okay - just tested.
Try removing/reinserting the InvoceCode activity.

Cheers

Downgrading the systems activities package to 20.10.4 would resolve my issue but I have other components that are dependencies.

is their a way to make the change without using the Invoke code activity?

we can do it

  • within a for each row (which also will work in the majority of cases for large data volumes)
  • within an assign activity with a different LINQ using the itemArray reconstruction approach

How to Update Data Column Values of a Data Table | Community Blog

Hi,

LoadDataRow method will help you, for example

CleanTable = CleanTable.AsEnumerable.Select(Function(r) CleanTable.Clone.LoadDataRow({r("Column1"),r("Column2"),DateTime.ParseExact(r("Effective Date").ToString,"MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd 00:mm:ss")},False)).CopyToDataTable()

Please modify argument of LoadDataRow to actual columns.

Regards,

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