New Thing created in database before workflow step

Hello,
I am working on an app which will check if a user’s company already exists when the user creates their account. If the company exists the user is set to Not Active and a pop up appears. If the company does not exist, the workflow will create the company and run a set of actions.
The issue I have is Bubble is creating the company immediately when Submit is clicked so the workflow always triggers that the company exists.
I changed the search for company to a custom event since that workflow should fully complete before any other steps are triggered, however that isn’t what is happening. I am stumped on where the issue is in the workflow.

This is the workflow.


This is the custom event.

Steps should be as follows:
Custom event - does the company exist? Yes

  • create the user, change the user status to Not Active, show popup and terminate workflow.
  • Custom event - does the company exist? No
  • create the user, create the company, make some other changes to the database.

In debugger after Submit is clicked, the check if the organization exists is returning true, however the database entry for the company did not exist already.




image

For anyone that finds this and runs into the same issue, this appears it was due to the workflow execution order. Bubble was creating the organization database entry at the beginning of the workflow even thought the create step wasn’t until step 6. I solved this by placing everything inside custom events and triggering them in sequence with conditionals as needed.