I’m trying to figure out how to get custom code actions (not custom workflow actions) to change the exectution state. All custom code actions have the enumeration “hs_execution_state” as an output option, but I haven’t been able to find ANY documentation on this.
There is the same enumeration on custom workflow actions but that doesn’t help me.
How does one use this enumeration state to give valuable feedback in the workflow? I’ve tried setting it using the callback method, but all I get are 2 different outputs for the same variable:
Hey @Zayne, thank you for posting in our Community and sharing screenshots about it.
Depending on the value of “hs_execution_state,” you can control the flow of your workflow. For instance, if the custom code action encounters an error, you might want to trigger alternative actions or send notifications to relevant stakeholders.
Hi Pam. Yes, I’m aware that the outcome of the custom code can control the flow of the workflow after the code. What I’m struggling to find information about is
what causes the custom code to reach one of those states?
How can I coerce the custom code to reach one of those states?
I could also just set and return my own variable to control the flow, but I would like to be able to see in the workflow logs if the custom code didn’t finish successfully, and for what reason. At the moment, even if one of my custom code blocks fails to, for instance, call an API, it is always marked as successful.
You cannot use the value hs_execution_state in your code since it is outputed after the code is ran.
hs_execution_state will be set to “success” if all your code run without encountering any error.
You need to handle errors in your code with try/catch or .then/.catch.
When you want your code to break and stop and hs_execution_state to be equal to “Error” you need to throw errors properly in your code with
throw new Error('Whoops!')
if you console.log the error, hs_execution_state will be set to “Success” anyway.
A good way to handle error is to wrap you call to apis in try/catch blocks:
try {
//call an external api from here
} catch (error) { // this line will catch the error if the request in the try block fails
throw new Error(error); // this line will log the error in the console and set the hs_execution_state to "Error"
}
The following would set the hs_execution_state to “Success” even if there was an error when executing the code:
try {
//call an external api from here
} catch (error) { // this line will catch the error if the request in the try block fails
console.log(error); // this line will log the error in the console and set the hs_execution_state to "Success" because this is just logging some text in a string even if the content of that string is in fact an error message
}
Sincerely yours,
The Wizard of Hubs
Don’t forget to mark my reply as a solution if you are satisfied. If not, do not hesitate to ask me anything!
Setting hs_execution_state to one of the values listed in the enumeration of hs_execution_state on the custom code output seems to work.
Here’s an example: