Sending an email notification when project fails

If you ever need to send an email notification in case of project failure here is how you can do it:

The example below uses a new setting in the “Iterate” transformation that allows catching errors in the executed project: “Collect errors and continue”. Therefore, in order to capture error of a project we need to iterate the project once in a wrapper (master) project, capture errors in “Iterate”, and if there are errors – use a conditionally derived table to run the “Send email” action.

Here is how to use the example:

  1. Save both projects into a folder.

  2. Open “email-on-failure.morph” and configure the embedded email connector in it, and the “Send email” transformation (connector, recepient, etc.).

  3. Set the parameter “Should fail” to NO and run the project. It should run module “Submodule” and complete successfully, without email notification sent. Column “Iteration errors” is empty.

  4. Set the parameter “Should fail” to YES and run the project again. Module “Submodule” should fail, which produces an error value in “Iteration errors” column. This activates table “When failure” and executes “Send email” in it.

Bonus tip: Since “Iterate” allows specifying the iterated project using a parameter, the master project can be reusable – provide it with a project to run and a message text to send.

UPDATE 5/12/2021
The example has been updated to use features available in the latest version. Also added a 2nd group (tab) that shows an alternative solution using the “Skip” action.

email-on-failure.morph (8.9 KB)

3 Likes

Hi Dmitry.

I am trying to get my head around this one.

What if you have a project that has a few potential fail issues?

I am updating different tables in a db and the project can fail on any of the updates.

To simplify it, I am adding an EasyMorph Example where I have 3 tables and all or any of the table actions can fail.

Thanks

EmailFailure.morph (13.9 KB) *Data - Copy.zip (251.4 KB) *

Hello,

Use parent module to get error and send email if error is raised.

This can happen for sure. What would you like your workflow to do in this case? Should it behave differently depending on the fail cause? If yes, how exactly it should behave?

Hi Dmitry
I want to get notification if any of the workflow fail (which error) and notification if the the project was successful (no failure).

Thx
Rykie

Rykie,

In the error capture mode, the Iterate action appends a new column with the errors that caused the iterated workflow to fail. It doesn't matter where exactly in the iterated workflow the failure occurred. Also, when an action fails, the workflow stops working. No other actions are executed.

In this case, add another "Send email" action in the "When NO failure" table which is executed when no errors occured. The action should send a notification when no failure occurs.

Thanks, Dmitry

It seems there may be a challenge here associated with parameters in the iterated project. If some of these parameters need to be set at runtime, they would have to be included in the master project and passed to the iterated project correct?

Yes, that’s correct @jcaseyadams .

Hi Dmitry,
Could you share a morph / suggest how to send email when a project fails in the older version - 4.6.2.13. Your morph shared need later easymorph version , which unfortunately I cant install for company reasons.
Totally new to Easy Morph

Hi Naza and welcome to the Community!

I can’t share a morph in v4.6, but here is how you can reproduce it:

0. Open project

Open the project to which you want to add the email notification.

1. Create a wrapper module

In your project, there is a start module. It’s marked with a flag in the right sidebar. By default, its name is “Main”.

Create a new module. Name it, for instance, “Wrapper”. Right-click it and make it the start module.

image

2. Add the Call action

In the Wrapper module, add the “Call another module” action and configure it as below.

Notice that the action must use the “Capture errors and continue” mode. In this mode, when the called module fails, the action won’t fail but return a list of errors that caused the called module to fail. When there are no errors, the output of the action won’t have any errors (as in the screenshot above).

3. Add the Skip action

After the “Call” module, add the “Skip actions on condition” action. The action skips all the actions that follow it (in the current table) when its condition is fulfilled. The action should be configured as below.

Since the Call action in front of it will only return rows with errors from the called module, the Skip action will make EasyMorph skip all the following actions (in this table), if there are no errors.

4. Add the Send Email action

Finally, add the “Send email” action after the Skip action. Configure it as necessary. This action will be executed only when the module called in the Call action fails, and skipped otherwise.

Note on parameters

If your Main module has parameters, you may need to re-create the same set of parameters in the Wrapper module (you can simply copy/paste parameters in the Parameter Editor) in the Wrapper module, and have them assigned in the Call action to the parameters of the called module.

2 Likes

A post was split to a new topic: Use the original error(s) within the ‘Halt’ action or something similar