If condition continue

Hello all, please help. I have this IF condition and I want the bot to stop the process after sending the outlook email and not move to another activity after that IF block. I want it to start again the process from the beginning. I couldn’t use ‘continue’ there

@Anelisa_Bolosha1,

  1. Separate the Logic into Another Workflow:
  • Create a new workflow specifically for the email sending logic. This helps in isolating the email-related tasks from the main workflow, making it easier to manage and debug.
  1. Throw Exception in the Child Workflow:
  • After the email is sent in the child workflow, include a step to throw an exception. This is crucial because it allows you to handle errors or unexpected situations that might occur during the email sending process.
  1. Surround the Main Workflow with Try-Catch:
  • In the main workflow, where you will be invoking the child workflow, wrap the invocation of the child workflow within a try-catch block. This ensures that if an exception is thrown in the child workflow, the remaining steps in the main workflow won’t execute.
  1. Control Flow to Catch Block:
  • When an exception is thrown in the child workflow, the control will flow to the catch block in the main workflow. Here, you can log a message to understand what happened. This logging is important for debugging and monitoring purposes.

Here’s a simplified example in pseudocode:

Main Workflow:
try {
    invoke Child Workflow
    // Other steps that won't execute if an exception is thrown
} catch (Exception e) {
    log("An error occurred: " + e.getMessage())
}

Child Workflow:
sendEmail()
throw new Exception("Email sending failed")

In this example:

  • The sendEmail() function is part of the child workflow.
  • After sending the email, an exception is thrown to simulate an error.
  • The main workflow catches this exception and logs an error message.

LLM helped me to rephrase my logic more clearly.

2 Likes

@Anelisa_Bolosha1

You can have rest of the code under else block. So nothing is there after if statement.

Regards
Sonali

1 Like

Hi @Anelisa_Bolosha1

Try to Use the terminate workflow activity right after sending the Outlook email inside the if block. This will stop the current process.
If you’re using reframework, set the transactionitem to nothing or adjust settransactionstatus.xaml to reset the loop.
Alternatively, you can place everything inside a loop like while or do while and use break and continue logically to restart from the beginning.

If you found helpful please mark as a solution. Thanks
Happy Automation with UiPath

1 Like

This is very helpful thank you so much, I will have to rebuild/restructure my bot properly for this one.

1 Like

Thank you, this was the quick solution :slight_smile: , as the bot was already in production.

2 Likes

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