‘I think’ the problem is that the first task of creating items is not completely finished when the second one starts. But I don’t know how to add a waiting time between 2 tasks … and I’m not even sure that’s the problem.
Yes, you’re right. You’re encountering race conditions. This is generally an issue with Lists on data types.
You can reduce the risk of this by assigning an interval between workflows. On your Schedule API workflow on a List (if using it), add an interval of 1 second or 2 seconds.
Now, if you have one trigger setting off multiple workflows all at the same time, there’s no easy solution (short of an overengineered queuing system). I’d just avoid using the list at all and instead jut Do a search when you need it rather than accessing the list directly.
the only way to reliably get this to work is to do a recursive workflow with a slight delay between the steps.
you still need a slight delay between the steps since if it is super fast to process bubble still drops records even though they get added sequentially.
I often do this like
schedule api workflow where
current number starts at 1
max number is 10 (number I want to create
create the thing
add to other thing
schedule same workflow again +1 to current number and 0.3 second delay (have condition to only run this after add to thing is not empty)
only schedule it if current is less than max number
you definitely want to do simple math here - plus 1 to the current number. DO NOT count created records as that is a search (heavier) and maybe the creation step fails and so you get an infinite loop…
backend api is best for this workflow since the front end could be interrupted and stopped before all X items are created and added to list (ie user navigates away from page)
Another potential solution I recently used - when creating the list of things via API workflow, I included a field of type text. When triggering the workflow, I generated a random set of characters that I included for this field, and triggered another workflow that when the count of things with that random set of characters count = the number of things scheduled to be created, to add those items to the other thing. This prevented any potential race conditions, and added them all in 1 step once they were complete.