Out Arguments data not being transfered when an error occurs

Hi there,

I think the current issues already reported are a bit different.
While using REFramework and the bot is executing the actions in Process.xaml the Datatable io_dt_TemplateFileData(From now DT) is extracted properly in the Workflow EKR_Retrieve_data. However the DT is not being transfered above when an error occurs in PrimaryData_Export.xaml.

In this picture the DT is read properly in EKR Workflow

In this picture the argument io_TemplateFileData is assigned to a variable

This is the result when the bot fails (Empty). The data was not empty before getting out of Process.xaml

Can someone help me please?

Thanks in advance,
Fer

@Fer_Fer

It is expected that when there is an error no variables would be paased

One way is to use write the table to an excel and read it in the exception block

Second is to use a try catch aound the part and save it to exception variables before rethrowing

Next is to serialize the dattable and store it in asset and read the asset back in exceotion block

Cheers

@Fer_Fer you need to check basic thing
1 Check argument Type "in or out "
2 Check Datatype Pass and received data type

Best Practices for Data Type Passing:

  1. Use Arguments:
  • Leverage the Arguments pane in UiPath Studio to define input and output data types for your workflows.
  • This ensures type safety and clarity during development and execution.
  1. Explicit Casting (When Necessary):
  • If you need to convert data types within workflows for specific operations, use explicit casting techniques (e.g., CInt(value), CStr(value)) with caution.
  • Consider alternative approaches (e.g., using the correct data type initially) to minimize casting and potential errors.
  1. Clear Variable Naming:
  • Assign descriptive names to variables that reflect their data types.
  • This improves code readability and maintainability.

Resolving Data Transfer Issue:

Scenario 1: Missing Argument in PrimaryData_Export.xaml

  1. Verify that PrimaryData_Export.xaml has an argument defined to receive the io_dt_TemplateFileData Data Table.
  • If missing, add an argument of type DataTable and link it in the Invoke Workflow activity calling EKR_Retrieve_data.xaml.

Scenario 2: Exception Handling:

  1. Implement error handling in EKR_Retrieve_data.xaml using Try Catch blocks:
  • Wrap the Data Table extraction logic within a Try block.
  • In the Catch block, handle exceptions gracefully, potentially logging them and potentially providing a default value for the Data Table.
  1. Modify PrimaryData_Export.xaml to handle the possibility of an empty Data Table:
  • Check if the received Data Table is Nothing (UiPath null equivalent) before using it.
  • Take appropriate actions (e.g., logging, skipping operations) if the Data Table is empty.

Additional Considerations:

  • Ensure proper execution order in the REFramework workflow. EKR_Retrieve_data.xaml should execute before PrimaryData_Export.xaml.
  • Consider using Rethrow if the error handling in EKR_Retrieve_data.xaml isn’t sufficient and you want to propagate the error to the main workflow.
  • Review your logging strategy to capture potential errors during execution.
  • Utilize debugging tools (UiPath Studio’s debugging capabilities) to step through your workflows and pinpoint the issue.

First of all, thanks a lot for your quick and elaborated answer

  1. Arguments in/out are checked properly
  2. Datatype passed and received are the same

Best practices

  1. Done already
  2. There was no need to convert datatype
  3. Done already

Scenario 1: PrimaryData_Export.xaml has an argument defined properly

Scenario 2:

  1. I will try the try catch block + rethrow
  2. Done already

Thanks again,
Fer

@Fer_Fer,

You can use this approach.

Use Try catch in the workflow you are trying to invoke and declare one additional out argument of type System.Exception. In catch section assign the exception to out argument we declared. Don’t throw or rethrow the exception.

This will result in peacefully execution of the invoked workflow so will return all the Out arguments. Read those values in the calling workflow and then check if the local variable which will hold out argument value of the exception isnot nothing. If true it means there was exception and you can take further action you want like throw it or handle it as per requirement.

image

Here is sample code:
Test1.zip (4.2 KB)

Thanks,
Ashok :slight_smile:

Reminder that, when using an LLM to generate your reply you are supposed to indicate you used an LLM.

Your response looks straight of an LLM considering the formatting, bulletted points and some of the text. Please follow forum guidelines and note you used an LLM to make your reply.

This is default behaviour UiPath and .NET I believe.

Some variables will appear to be populated after an error but thats due to them being a ‘by Ref’ argument instead of a ‘by val’ argument. A by ref means you are referencing the same object in memory, so the out workflow actually isn’t even needed. You cannot explicitly control if its a 'by ref in UiPath so its usually that ‘simple’ data types are by val and more complex ones are ‘by ref’.

It appears Datatable is a ‘by val’.

As such you have to do some work to make this happen to ensure no error ever gets thrown or the data is passed out via the error, a solution such as the one provided by Ashok is a possibility.

I feel like you should revisit the design somehow though since this seems to be a problem ridden scenario.

Thanks Ashok! I really appreciate your answer

The best solution to not overcomplicate my process was to use GLOBAL variables.
image

In fact, they seems to be actually a very clean solution to avoid passing into workflows for example Config data

Hope this can helps others with their same issue.

1 Like

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