APIs & Integrations

crossm98
Member

Handling a Custom Code if it fails

Hi,

I have built a custom code in a workflow. My goal is, if the custom code fails (a.k.a. hs_execution_state != Succeeded), I want the workflow to send a Slack notification, and then finish. If not, I want the workflow to continue its course.

Is that possible?

0 Upvotes
3 Replies 3
MatthiasKunz
Participant | Partner
Participant | Partner

Handling a Custom Code if it fails

Hi @crossm98 , @Jaycee_Lewis ,

easiest option I can see off the top of my head would be to include a step either in the same or in a separate code step to send a JSON payload in order to post a slack message if the original code has failed. Slack has an API so you could post a message to a channel there readily enough. You can find some support for this online: https://stackoverflow.com/questions/50187220/is-there-any-way-to-post-a-webhook-using-javascript 

There might be a more elegant solution, if you manage to feed the state into an if/else branching in the workflow and then send a message and finish / continue the rest of your workflow. https://knowledge.hubspot.com/workflows/use-if-then-branches-in-workflows 


Cheers,
Matthias

Jaycee_Lewis
Community Manager
Community Manager

Handling a Custom Code if it fails

Hi @crossm98 👋 Thanks for your question. To check my understanding, is your goal to have a form of an If/then statement after your custom code executes? Based on the outcome? If the code fails, then send the Slack notification. Is that correct? 

 

I looked at the documentation here, Custom code workflow actions, but didn't find a great match for what you are describing. 
 

Hey, @miljkovicmisa @Teun @MatthiasKunz, do you have any custom-coded thoughts or suggestions 😊 for @crossm98?

 

Thank you very much! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
crossm98
Member

Handling a Custom Code if it fails

Hi @Jaycee_Lewis,

That's precisely what I'm looking for. Make the custom code run. If it fails, send a slack notification and finish. If it runs correctly, continue the workflow.

0 Upvotes