Workflow not finding newly created contact

Hi

I have 2 Data Types:
Contacts

  • Name
  • Email

Enquiry

  • Contact (links to Contact Data Type)
  • Subject
  • Message

I have a contact form on our website. When the form is submitted, it creates a new contact (not a user) in a Data Type called ‘Contact’, but it struggles to populate the Enqury data type with the associated contact. I cannot work out what is going on.

So I have this workflow:
Create a new thing (Contact)
Only if email address doesn’t already exist in contacts table.
This works fine.

Next Step…
Create a new thing (Enquiry)
Contact = ‘Do a search for contacts where email = input email’s value: first item (from form)’
I’m using this rather than the results of step one because if the contact already exists in the database there are no results from step 1.
Subject = Input Subject’s Value
Message = Input Message’s Value

It fails to populate the contact field in the Enquiry data type.

However!!! IF the contact already exists, it populates it successfully in the Enquiry data type.

So i’m confused. It seems like it is performing the search to retrieve the contact from the database before it has finished generating the new contact. Proof of this is the fact that it finds the contact and works successfully if it isn’t having to first create a new entry for a new contact.

Is it possible to Pause a workflow slightly, or get it to wait before it continues executing the rest of the workflow?

Any suggestions would be greatly appreciated. Many thanks

Hi there, @chris.senior… I am guessing you are correct about the step that creates a new Enquiry running before the step that creates the new Contact has completed. There are a number of ways you could fix the issue, and I think I might go about it by adding a couple more steps to the workflow. I would leave the first step as-is, and then I think I would create the Enquiry in the second step, but I wouldn’t populate the Enquiry’s contact field. Then, in the third step, I would make changes to the result of step 2, and I would populate the contact field with the result of step 1 only when the result of step 1 isn’t empty. Finally, I would add a fourth step that makes changes to the result of step 2, and this step would populate the contact field with a search for the appropriate contact only when the result of step 1 is empty.

Anyway, that’s one way I think you could go about addressing this one, and I hope it helps.

Best…
Mike

2 Likes

Yeah, you wouldn’t attach the Enquiry to the Contact by “doing a search for” the Contact. You would do it with steps like this: (1) Set some state (it can be anywhere) to Search for Contact where email is email in the form :first item (2) Create new Enquiry (3) Create new Contact only if the state from step 1 is empty (4) attach Enquiry to Contact that is the result of Step 3, only if Result of Step 3 is not empty (5) attach Enquiry to Contact held in the state from step 1, only if Result of Step 3 is empty (alternatively, only if the state from step 1 is empty (6) if the page allows the user to submit another Enquiry right away, set the state set in Step 1 to empty (null it back out)

Using a state in this way is necessary because when new Things are created, they appear (to the page) as if that Thing actually exists in the database (it is assigned a unique ID in the page). But it takes time for the Thing to actually be created in the db and show up in a Search. So, the page “knows” that this object will exist and already knows its unique ID, and thus can operate on that object, because we already know its unique ID. It can even modify the object (via make changes to a Thing) and will act as though this has happened immediately, even though the changes have not been made in the database yet.

So what I describe above is the basic design pattern one should use when creating new Things. (Hold on to the Thing by getting it as the result of the Create action. Don’t “forget” it by doing a search for it.)

Edit 2: I wrote this up as if you want to attach the Enquiry to the Contact, though @chris.senior might be wanting to attach the Contact to the Enquiry… or both. All of the above still applies. The issue is that the Enquiry is always new, but the Contact might not be. We have to hold on to all of these references within the workflow (a state we evaluate at step 1 that tells us if Contact needs creating or not, the newly-created Contact (should we have to create it) and the new Enquiry that we will create regardless).

Aside, one might note that such a workflow is needlessly complex. Steps (4) and (5) are the exact same action (Make Changes to a Thing), they just have a different argument for the Contact.

If the Expression Builder had a JavaScript style :or operator, we could (for Thing to modify) just say some_state :or Result of Step 3 which would return the first non-empty argument. (Similarly, if we had a JS style :and operator, we could return the last non-empty argument.)

Thank you @mikeloc and @keith for your solutions.

I’m still getting my head around some of the mind-bending workflows Bubble.io promotes and haven’t yet explored States. I think that will be my next challenge.

The good news is that I have managed to implement the suggestion by @mikeloc with success.

By getting Bubble to create a thing and then update a thing as a separate step it is acknowledging the creating of the contact and populating it in the respective Data Type.

It is very convoluted and I do feel like it is an unnecessary number of steps to get it to do what @keith clearly points out could be very simple with Javascript. Nevertheless we have a solution and can move on with the development so thank you both for your insights and solutions.

I will explore the use of states and maybe that will provide a solution with less steps for these kinds of activities in future.

Thank you

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.