Hi All,
I am using the below expression to find the maximum date in my data table. Currently its a single row in DataTable but at run run times it may contain multiple line items with multiple dates. I need to find the max date . But I am currently getting an error. “Assign: Sequence contains no elements”
ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r((“Date”)).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r(“Date”).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString(“MM-dd-yyyy”)
Thanks in Advance
Yoichi
(Yoichi)
June 8, 2023, 2:01pm
2
Hi,
Your expression seems no problem. Can you check (share) content of DataTable? Please set Breakpoint at the activity then check it in Locals panel.
Regards,
dutta.marina:
DateTime.TryParseExact(r((“Date”)).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)
Hi @dutta.marina ,
I believe the TryParseExact()
does not work as expected, because of the format mentioned.
Check the Datatable value by Debugging the workflow. The format might be in the below way :
MM/dd/yyyy HH:mm:ss
So you might need to adjust accordingly in the Expression, maybe to the below:
ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("Date").ToString,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r("Date").ToString,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString("MM-dd-yyyy")
postwick
(Paul Ostwick)
June 8, 2023, 2:04pm
4
Look for any empty Sequence activity in your project.
Hi Arpan,
I tried to debug the DataTable .The format is
Anil_G
(Anil Gorthi)
June 8, 2023, 4:39pm
6
@dutta.marina
as per the format please use M/d/yyyy
in both parse and try parse
Also to avoid future errors it is better you use a if condition to check if atleast one row is returned from where condition
ExtractDataTable_Invoice.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("Date").ToString,"M/d/yyyy",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Count>0
on then side use the expression on else side you are not getting any rows that are matching
cheers
Thanks @adiijaiin It worked.
Thanks @Anil_G for the solution
1 Like
system
(system)
Closed
June 11, 2023, 5:11pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.