Skip to main content
Solved

Create Automation Failure with custome script


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?

Best answer by kuovonne

Yes, throw a JavaScript exception. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw

View original
Did this topic help you find an answer to your question?

6 replies

kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5996 replies
  • January 13, 2023

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. 

 


  • Author
  • Known Participant
  • 11 replies
  • January 13, 2023
kuovonne wrote:

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. 

 


Hi, what kind of error should I throw? a js exception?


  • Author
  • Known Participant
  • 11 replies
  • January 13, 2023
Zehava_Rubin wrote:

Hi, what kind of error should I throw? a js exception?


@kuovonne Can you write out the code now so that I can understand what you are suggesting?


kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5996 replies
  • Answer
  • January 13, 2023

  • Author
  • Known Participant
  • 11 replies
  • January 13, 2023
kuovonne wrote:

Thank you!


  • Participating Frequently
  • 8 replies
  • May 23, 2024
kuovonne wrote:

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. 

 


I'm having issues getting output.set() to run when I'm throwing an error. Basically, trying to set a field on the record called Status and set it to "Error". But when an error happens, whether I catch it or otherwise, the output.set does not work. In fact, it erases it above. 

Is there a workaround to update a record within a script before throwing an error? Specifically within a catch statement, updateRecord doesn't work within those catch statements it doesn't seem.


Reply