Jan 12, 2023 04:54 PM
If I have a custom script as an action in an automation, is there anyway to have a catch or else statement that would create a failed automation notification like there is for the built in actions?
Meaning, how can I set up a notification system if a custom script fails?
Solved! Go to Solution.
Jan 13, 2023 08:10 AM
Yes, throw a JavaScript exception. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
Jan 12, 2023 06:34 PM
If you want your script to fail and stop the automation, you can throw an error. Sorry I cannot format the text as code while on my phone.
throw "this is an error to cause the automation to fail"
You might also want to console.log() some key variables to give more info about why you want the automation to fail.
Another option is to have the script use output.set() to indicate the success of the script. Then use conditions to either take any additional actions of the script was successful, or have an email action if the script says it was unsuccessful. You will probably get the email from the automation email action sooner than the email notification about the failed automation. Of course it might be harder to identify the exact run in the history of it doesn’t fail.
Jan 12, 2023 06:39 PM - edited Jan 12, 2023 06:40 PM
Hi, what kind of error should I throw? a js exception?
Jan 13, 2023 07:01 AM
@kuovonne Can you write out the code now so that I can understand what you are suggesting?
Jan 13, 2023 08:10 AM
Yes, throw a JavaScript exception. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
Jan 13, 2023 08:59 AM
Thank you!