Need help fixing a buggy loop


I’m creating a payment workflow for my art selling platform. You have 3 ways of paying: buy, buy as installments, or just rent.
With installment and rent you will have a monthly invoice to pay, so I wanted to create as many invoices as necessary.
For example, when the customer wants to pay for the artwork as an installment for 3 months, as s/he pushes the submit button, a workflow creates the first invoice and then the loop will create 2 more (3 in total, one for every month), with every one of them having a different due date and invoice number, everything else stays the same.

I got the loop working for installment workflow, but as I’m creating pretty much the same loop for the rent workflow, the loop just does not work. I mean it works, it saves everything correctly except one field. And that’s weird, because the loop works for the first iteration and does not work for the next ones. Well only for one field, but still…

On the second picture, the first entry is created manually, 2 and 3 are made with the loop. As you can see, the 2nd entry (1st iteration) works as it’s supposed to, but the 3rd entry (2nd iteration) has a hole.

I’ve been stuck here for such a long time, tried so many ways, but since it’s a backend loop, I can’t debug it using the bubble debugger. Somebody help me, I’m starting to loose it haha :smiley:

Adding a diagram of the workflow just in case

You should provide your Schedule API Workflow loop setting + Step 2 Make change to Art sale setting (more the “Things to change part”)

Hopefully this is what you meant.

Do step 2 work correctly and the Art is added to invoice like it should?

Yes, you can see on the picture with the table the ‘Art sale’ column has the same unique id.

In step 2, the field update is “Invoices” not Art sale. Your table doesn’t show this field.

No, it makes a change to the current Art Sale that had just been created. The purpose of the loop is to create an invoice for every month and add it to the Art Sale. So when a customer wants to pay as an installment for 3 months, as s/he pushes the button, it creates a new Art Sale, creates as many invoices as necessary and then adds the newly created invoices to the Art Sale

My question is to validate that this step is working and finding the correct item like you expect. If you check invoice field and the step 1 created item was not added, it’s probably because your search return nothing. So when you go in step 3, result of step 2 is empty too.
In step 2 your are updating the invoice field.

Also, I think you should not need a search to do the step 2 and you should provide it directly into the Scheduled API by adding a parameter for that instead.
The initial workflow should “create a new Art Sale”, Schedule an API WF. You should have a field that will contain the iterator and a field that will be art sale that will refer to step 1 created art sale.
In loop, Create invoice, and you should have the “art field” directly there using the art sale parameter instead, make change to thing (“Art sale from parameter, not doing a search”) invoice , add Step 1, schedule API WF again.

Also, be sure that you are not having an issue with privacy setting. The first iteration is done by “you” but other iteration are not done on behalf the user like the first one

Oh, I checked the Art Sale data type itself and it does have three invoices saved as needed.
It saves the invoices to the Art Sale, but does not save the Art Sale itself to the invoice. I guess the bug must be in the third step during the second iteration.

Btw, all data types: artwork, art sale, invoice are connected and have each others unique IDs saved so I could get access to them easily.

I really believe that you should reduce number of step by sending more data to your scheduled WF. You said that are are the same for all of them, so why not to send it in the Scheduled WF instead of adding another step?

With the current setting I don’t see any problem but it’s always hard to debug in Backend WF. You can check your logs to validate each step.

I’m gonna call it a night for today, will give it a look again tomorrow. Thanks for the help! Will give you feedback tomorrow.


1 Like

Okay so I tried your suggested parameter idea, definitely more reliable than doing a search. AND IT WORKED! Big thanks! I changed the other loop to use the parameters also, much more reliable, didn’t even think of it before. @Jici

1 Like

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