How to wait for multiple data that doesn't exist yet?

Hey Bubblers,

I’ve been pulling my hair for the past few hours trying to figure this out. Hope you guys could help me here.

How should I wait for a data that doesn’t exist yet?

For context, I have a workflow that creates a product with lots of relationships with other data types. My frontend workflow schedules an API WF in the backend to create the product together with the other data types.

What I want to do is to have a loader that automatically closes if the product and the other data types have been fully created.

This would’ve been pretty simple if the process was in the frontend since we could use custom events to really make sure if the process has been completely finished but for these workflows, I’m using the backend.

I’m trying to use the action trigger a custom event when data changes to serve as an indicator if the data types have been created but then again, how should it wait for a data that doesn’t exist yet, let alone multiple data types that needs to be checked instead of one? It’s not like the database trigger where we could use the expressions thing before change is empty and thing now is not empty

TL;DR

How can I notify frontend when multiple data types have been fully created?

Pretty sure there’s a simply solution and I’m just missing something out. Would greatly appreciate any help :pray:

Thera are different ways of doing it.
One example is:

  • let’s assume you have a backend workflow that created a “product”. You need to assign an id to this product, not bubble automatic id because you need to be able to search for it without knowing its bubble id.
  • create a repeating group. It will be used for storing data, not for display.
  • add a state id of type text to the repeating group, and another state show of type yes/no defaulting to “no”
  • set the source of the repeating group to “do a search for products” with constaraint “mycustomID = repeating group id”
  • have your loader set to “invisible on page load” and add a condition to show it if the repeating group count is <= 0 and repeating group show is “yes”
  • on the workflow where you schedule the backend workflow as first action set the state of the repeating group: id → the id you will use to create the product in the database, show → yes

now when you trigger the workflow the loader will show because the search will be empty and show will be yes.
As soon as the product is created in the database the data source of the repeating group will be updated and the loader wiil hide because the length of the list in the repeating group is > 0.

I hope this can help.

Cheers
Mariano

2 Likes

There are several ways to do it…

One option (possibly the simplest to implement, and probably how I would do it) is to create a Datatype of ‘Workflow Log’… with fields such as ‘Workflow Type’ (text or an Option Set), ‘Total Actions’ (number) and ‘Actions Complete’ (number), or 'Percentage Complete (number), and/or ‘Complete’ (yes/no) etc.

Create a new Workflow Log entry at the start of your page workflow, pass it to the backend, and update it as the backend (presumably recursive) workflows are completed (i.e. update the percentage complete, the number of completed actions, or just have a completed yes/no field).

Also pass the log into a group (or custom state) on the page, then just watch that log on the page, and when it changes to 100%, or the completed items count is the same as the total items count, or the completed field is yes, you know it’s finished, so you can trigger whatever on-page actions you need to trigger.

You can always delete the Log entry at some point after completion if you don’t want/need to keep it)

You can also do it without creating a log, just by monitoring the count of the various things related to some other thing, but it’s usually a bit more complex to set up…

As always, they best way to do it will be dependant on the specifics of your app and the complexity of the workflows…

3 Likes

This method where you create the log entry as first action and use it to keep track of the process is better that just search for the “real” data in the database.
I did a test and the search get cached by bubble for 10 minutes, so sometimes it does notify sometimes it doesn’t.

2 Likes

These are both really smart answers, which I’ll utilise. :+1: :+1: :+1: (and hadn’t thought of)

2 Likes

Hey @dorilama,

Thanks for taking the time to help out! Appreciate your response :bowing_man:

I got the gist of your process but I wanted to ask a clarification regarding this part:

For the value of the stateid in the repeating group, I would have to calculate a random string for it, and have that value populate the mycustomID field of product, right?

If I would have to calculate a random string, wouldn’t this create a possibility of duplicates? Although it is random, it still doesn’t rule out the possibility of creating the same string again.

Pardon my noobness but regarding your “test”, were you referring to your own process? If so, what might be the reason why it is getting cached by bubble? I’m relatively familiar of what caching is but not in this context…

Would greatly appreciate your response!!!

Best,
Nino

Hi @adamhholmes,

Again, thank you so much for helping out! You and @dorilama are both rockstar bubble devs :metal:

Just also wanted to clarify:

Does the workflow log need to have a relationship with the product? I’m assuming no, right?

I also really like the flow that you just suggested since the workflow log has value and can thus represent a dynamic loader!

Looking forward to your response!

Best,
Nino

P.S. thanks for always helping out in the forum :bowing_man:

bubble applies its own logic to decide if making a request again. In my example it looks like bubble does not make the request again.
Because of this and the assumption that you have your own ids it’s better if you use Adam’s solution with the log object, pass it directly in the workflow and check a flag on it for the end of the process.

1 Like

Thanks Mariano!

Yeah, looks like I’ll be going with Adam’s suggestion. Thanks again for helping out!

May I ask you to please confirm this? I’m positive that I’m right here - just want to add it to my box of tips and tricks!

Yeah, super thankful to these guys.

same! I guess we both have to up our game :muscle:

If this all happens in one backend workflow, you can actually call that backend workflow through the API connector in your frontend (Like you would with any other API call) and it will wait until the workflow is completed to move to the next step

Connect with me: