Sequence in Backend Workflows - external API call triggers before all records are created


I know a lot of newbies asks that, I’ve red tons of topics before I’m writing my own.

Workflow for user is simple:

  1. User clicks a button
  2. X amount of records is created in DB and displayed to him

However the issue is on backend.

  1. Create X records with attribute Y (so done by Recursive Schedule API Workflow)
  2. Send it to external API (one of the parameters - list of unique ids searched by attribute Y)

The thing is - Step 2 is starting instantly and request is sent/received while Step 1 isn’t even close to finishing. I cannot relate to ‘Result of Step 1’ because it’s done as Scheduled Workflow API. I don’t even now the value (when I tried to debug - it was just a number as text). Tried to check if result is not empty - no luck, so I suppose it has some value as it’s starts, but not finishes.
Sometimes external request is called even before the first record appears (at least on a screen) - then it has some unique ids I cannot even find in correlated table. And this is intriguing as well.

I don’t want to schedule another workflow as it’s unpredictable. Records might be created nearly instantly or might take a minute to generate them all.
I also don’t want to split it into two different client workflow as user may close the page and then request won’t even trigger.
Tried to wrap workflow apis into custom event, but no luck. Maybe I did something wrong, because level of abstraction confused me (parameters of api connector call > parameters of workflow api call > parameters of custom event > another workflow api parameters to call the trigger)

Any advices on how to do this?

Looks like you have most of the concept of looping in the backend. Consider these points:

  • each workflow step is run for each loop, unless it has “only when” condition to (for example) make it an “end loop only” step, or unless the workflow is terminated (I had reliability issues with terminate workflow)

  • each loop doesn’t “remember” anything from the previous loop, so any preserved state needs to be passed to the next loop, for example via parameters or saved in the database.

Thanks, but that’s already working :slight_smile: That’s exactly how I developed creation of multiple records.

A lot of comments show respect to this one:

However I’m concerned of the following line:

  • Custom events run in sequence, not parallel. If Workflow 1 triggers a custom event that starts Workflow 2, Workflow 2 will complete before the remaining actions in Workflow 1 run.

I have tried creating two custom events triggers and wrapped in them my two backend workflows. Result was the same.

Ah, re-reading your post :laughing:

Try making step 2 a conditional step inside the loop

Actually you have your point in here, but I’d like to have reusable workflows if they have common steps in it.

But will try, thanks!

Me too, but every time I try to make it modular, the complexity increases way too much, and makes maintenance difficult.

Edit - Having said that, a conditional step in the loop consisting of “schedule/trigger a custom event” goes a little way there.