Stopping workflow execution

Hi there,

Suppose we have this workflow:
Trigger => X node => Y node

I need to stop the workflow whenever it reaches to X node, one way is to run throw new Error in execute function in the X node. But I prefer more peaceful way to stop a execution.

What do you think about this?

Hey @jellybean!

If you don’t want to execute the Y node, you can either disconnect the node, or disable it. If you want to execute it based on a condition, you can add an IF node in between the X node and the Y node.

1 Like

Thanks @harshil1712
I know I can use the If node, But I don’t want to. Also I don’t want to disconnect it. Is there any “coding” way instead of throwing an error?

A Function-Node returning an empty array.

return [];

If there are no items then n8n will stop.

2 Likes

Wow great @jan Thank you very much.

You are welcome. Have fun!

1 Like

Hi @jellybean! Glad you found the solution.

Could you share with us why you want to do this? I’m intrigued…

Sure @sirdavidoff , I was trying to implement wait functionality. But I found the “wait functionality PR” and it’s wonderful, so I ignored my implementation and just used that PR.

Uh that branch is not even in Alpha state yet. Is only PoC implementation without any proper testing. So the chance is for that reason quite high that you will run into problems at some point. Also will the DB probably still change, meaning that if you then upgrade to the final version it is best to export all your workflows and credentials and then reimport them in the stable version. As also the Wait-Node will for sure also change, will the workflows break and you then have to fix them manually.

Just that you know what to expect :wink:

1 Like

@jan Thanks for the explanations.
Actually I didn’t pull the branch, I just copied the codes related to wait node line by line! Also I didn’t copy the SleepTracker file at all, I’m using different approach: A crone job running on server that check database (sleepTill column) every minute. It seems stable to me :slight_smile:

I came across this thread looking for a solution to the very same problem:

I want to peacefully stop the workflow execution from a Code node when certain conditions are met. I tried to return an empty arry, but the Code node complains, that an array is returned instead of an object, see screenshot:

grafik

Is there a new way to stop execution of a workflow from within a Code block (without needing to manually add an IF node following the Code block)?

Works actually fine as described above. I assume you have it configured to run for each item which can not work:

You’re so right. Thanks for clarifying this. Switching the Code node to “Run once for all items” solves that issue.

That will save me tons of time as I don’t need to add subsequent IF nodes to all my Code nodes. Thanks!

Glad to hear. Have fun!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.