Formulas have a step type that allows a user to retry a formula execution in the case of an error that necessitates re-executing the entire formula. However, if the email in the Notification Settings for a formula instance is specified, each formula execution failure will result in an error notification email, which due to the formula execution retry step in a formula will result in a non-actionable notification. Imagine if your formula executes a 1000 times in a given day and for whatever reason 20% of the executions fail and are retried. This would lead to 200 unnecessary emails. That does not count any execution retries that fail and are retried again.
One could argue to switch off notifications on the formula instance and use the
notify.email() function in a formula script step. However, that will still end up with unnecessary notifications as the formula execution is still deemed a failure. So how can this be fixed? Please read on.
The following steps should help solve the above problem. Please note, some changes need to be made to your formula.
Disable notifications on the formula instance.
If your formula has notifications enabled, as shown below,
disable notifications by removing the email address from the Notification Settings as shown below,
and save the formula instance.
Now to the formula changes. The following formula is one that simulates a step failure and finally executes a Formula Execution Retry step when the previous step fails, i.e., it re-runs the whole formula.
We first add a configuration variable to our formula to set the maximum number of retry attempts for the formula execution retry. This variable will be used to determine if the formula is going to retry its execution or if it has run out of execution attempts. The illustrations below show this configuration variable and an example value for the formula instance.
Pro Tip: When adding a configuration variable to a formula that has existing instances, you do have to edit the instance.
We now need to add a step,
check-retry-attempt-count, between http-request-that-will-fail and the retry-formula steps.
check-retry-attempt-count step is a script step, and should be triggered as the
check-retry-attempt-count step is shown below.
Let's walk through the above logic.
- The script first tries to find the formula execution retry step by name, in this case
- For the very first occurrence of an error in the preceding step (the
http-request-that-will-failstep), i.e., when the formula execution has not been retried as yet, the step value will be
- This will result in the
check-retry-attempt-countstep throwing an error, and the formula being retried.
- If the
http-request-that-will-failstep fails once again during the retry attempt, then the
check-retry-attempt-countwill check the retry attempt number via the
attemptattribute of the
- If the attempt number is less than the maximum retry attempts set in the formula instance configuration, then an error will be thrown by the
check-retry-attempt-countstep, as in #2 above, which will trigger another retry of the formula execution.
- If the attempt number is equal to the configured maximum retry attempts then a notification email with the error message can be sent to a specific email address (for multiple email addresses, use comma separated email addresses). Note: Although the notification can also be achieved in the last step, i.e., the
gracefully-endstep, the email recipient and the error message may vary based upon which step resulted in this code path, so the
check-retry-attempt-countstep can be made specific to the trigger of the error message.
When the number of formula executions have been exhausted, the
check-retry-attempt-count step will end with a success, and can trigger a final script step to gracefully end the formula execution. In this example, the following code is implemented in the
In summary, when actionable notification are required from a formula, the
notify.email() function is a better approach to use than enabling the Notifications Settings on a formula instance.