Assign:
dtOrdersFiltered = dtOrdersFiltered.AsEnumerable.Where(function(x) Not dtPreviousOrders.AsEnumerable.Any(function(y) y(6).ToString=x(6).ToString)).CopyToDataTable
Whereby the Linq worked perfectly, but the issue I face is that if the original Excel file (datatable) does match the one it’s checking against, then it crashes because there’s no data.
Can I build something into this assign so if it carries out the instruction and thus, no data, it simply terminates?
You can try this way
1.Take assign activity pass like this
dtOrdersFiltered = dtOrdersFiltered.AsEnumerable.Where(Function(x) Not dtPreviousOrders.AsEnumerable.Any(Function(y) y(6).ToString = x(6).ToString)).CopyToDataTable
2.Take if activtiy and pass condition like this
dtOrdersFiltered.Rows.Count = 0
Then
No matching rows were found, so you can terminate the workflow or perform any other
Throw New Exception("No matching rows found. Terminating workflow
U can try like this with a assign activity which does validation within itself
In assign activity
dtOrdersFiltered = If(dtOrdersFiltered.AsEnumerable.Any(Function(x) Not dtPreviousOrders.AsEnumerable.Any(Function(y) y(6).ToString() = x(6).ToString())), dtOrdersFiltered.AsEnumerable.Where(Function(x) Not dtPreviousOrders.AsEnumerable.Any(Function(y) y(6).ToString() = x(6).ToString())).CopyToDataTable(), dtOrdersFiltered.Clone())
So it basically looks for match in assign activity itself
If there are no matching rows, we create a clone of the dtOrdersFiltered DataTable, effectively creating an empty DataTable with the same schema. This way, dtOrdersFiltered will always contain a valid DataTable, either with matching rows or an empty one.
Hi,
Yes, you can add a check to see if there are any rows in the resulting DataTable before attempting to assign it. If there are no matching rows, you can terminate the workflow or take other appropriate actions. Here’s how you can modify your assignment statement to handle this:
dtOrdersFiltered = dtOrdersFiltered.AsEnumerable.Where(Function(x) Not dtPreviousOrders.AsEnumerable.Any(Function(y) y(6).ToString = x(6).ToString)).CopyToDataTable
If dtOrdersFiltered.Rows.Count = 0 Then
’ No matching data found, terminate or take appropriate actions
Throw New Exception(“No matching data found. Terminating the workflow.”)
End If