My Studio Version: 2023.10.5
My Question: I have a datatable where I have 2 columns named Number and DateRange
I need to loop through datatable and should get the recent date among all those date values. Attached the picture below
My Solution : I tried with two solutions.
Solution 1 : Using DataTable
Step 1 : Build Data Table - With One Column Name (RecentDate) of Data type DateTime (System.DateTime) = Variable name is [dtInput]
Step 2 : Assign Activity - ExtractDataTable = new DataTable
Step 3: Read Range - Saved in Variable name called ExtractDataTable
Step 4 : Used For Each Row in DataTable activity
In Body - a) Assign Activity - strEndDate=Row(“DateRange”).ToString.Split({" - "},
StringSplitOptions.None)(1).Trim
//Above assign activity used to store the value from DateRange
column after the sign -
b) Assign Activity - ParsedEndDate = DateTime.Parse(strEndDate)
// ParsedEndDate is of variable type DateTime (System.DateTime)
c) Used AddDataRow activity to store ParsedEndDate value
Properties of activity - ArrayRow - {ParsedEndDate}
DataTable - dtInput
// I am getting error in this activity saying - Value of type ‘Date()’
cannot be converted to ‘Object()’ because ‘Date’ is not reference type
d) Assign activity - dtSorted (datatable) = dtInput.AsEnumerable().OrderByDescending(Function(r) CDate(r(“EndDate”))).CopyToDataTable()
e) Assign Activity - strRecentdate (String) = CDate(dtSorted.Rows(0)(“EndDate”))
Solution 2: Using List
Step 1 : Assign Activity - ListEndDates (List) = new List(Of DateTime)
Step 2 : Assign Activity - ExtractDataTable = new DataTable
Step 3: Read Range - Saved in Variable name called ExtractDataTable
Step 4 : Used For Each Row in DataTable activity
In Body - a) Assign Activity - strEndDate=Row(“DateRange”).ToString.Split({" - "},
StringSplitOptions.None)(1).Trim
//Above assign activity used to store the value from DateRange
column after the sign -
b) Assign Activity - ParsedEndDate = DateTime.Parse(strEndDate)
// ParsedEndDate is of variable type DateTime (System.DateTime)
c) If Activity - Condition = DateTime.TryParse(strEndDate,
ParsedEndDate)
//If Condition is True I am planning to add ParsedEndDate Value to List I
created.
My problem is I am unable to see activity named “Add To Collection” in Activity panel.
I have upgraded UiPath.System.Activities package to latest version.
Am I missing something If Yes how to add value to List which I created.
Need your help. TIA
Please let me know if you have queries in my question.