How to make workflow continue even if dt is empty?

Hi all,

I am trying to make my process continue running even though the data table contains no rows. Here is what I did:
image
In my if condition its:
dt_Output.AsEnumerable().Where(Function(row) Not (String.IsNullOrEmpty(String.Join(“”, row.ItemArray)))).CopyToDataTable() Is Nothing
If this is true then it will assign rowCount to 0. However right now it will crash at this part with this error output:
image
How can I make it so that it will continue running?
Thanks

Surround that activity with try catch and set the exception as system exception

Regards,

Hi @SRoyi

Assign: rowCount = 0

Assign: filteredDataTable = dt_Output.AsEnumerable().Where(Function(row) Not (String.IsNullOrEmpty(String.Join("", row.ItemArray)))).CopyToDataTable()

If ()

filteredDataTable IsNot Nothing AndAlso filteredDataTable.Rows.Count > 0
    Assign rowCount = filteredDataTable.Rows.Count

@SRoyi

If dt_Output.Rows.Count = 0 Then
rowCount = 0
Else

dt_Output.AsEnumerable().Where(Function(row) Not (String.IsNullOrEmpty(String.Join("", row.ItemArray)))).CopyToDataTable()

End If

Hi @SRoyi

  1. Assuming you have a DataTable variable named dt in your workflow.
  2. Add an “If” activity to your workflow.
  3. In the “If” activity’s condition, use the expression dt.Rows.Count > 0. This condition checks if the DataTable dt has any rows.
  4. Inside the “Then” section of the “If” activity, place the actions you want to perform when the DataTable is not empty.
  5. If you want to add specific actions for when the DataTable is empty, you can add an “Else” section to the “If” activity. Inside the “Else” section, place the actions you want to perform when the DataTable is empty.
  6. Optionally, you can also use a “Log Message” activity inside the “Else” section to log a message indicating that the DataTable is empty.

Hi @SRoyi

When we use read range workbook activity to read the excel, when there is no data in the excel it will throw the exception. If we want to handle this situation
Take the Use excel file activity and insert the read range activity inside.
After the read range Insert place If condition and check the Datatable.rows.count=0
Then you can insert the activities to proceed further.
else you can insert the activities to process further if it have rows.

Hope it helps!!

@SRoyi

Please try the condition like this

IsNothing(dt_Output) OrElse Dt_Ountput.RowCount=0 OrElse dt_Output.AsEnumerable().Where(Function(row) Not (String.IsNullOrEmpty(String.Join("", row.ItemArray)))).Count=0

Cheers

1 Like

Thanks! This worked just I wanted.

1 Like

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