Hi, I’m retrieving fake company data from an endpoint and looping through it. For each company I would like to create a xx number of invoices, each with xx number of products on. So I need think a triple nested loop. I can create one invoice per company no problem, but when I add in a repeat block with a counter, to be able to generate several invoices per company, I get a deadlock.
Also I’ve read through a lot of the community posts in here.. and they’ve been super helpful!
Hello @shazzaball,
I am not an postman-flow expert by any mean, but I tried to play around and reproduce your issue. I was not able completely replicate your flow as I did not have access to a Xero account right now. Still, I was able to reproduce it up until the last http request without deadlock on my side.
Checking the screenshot you shared, I wonder if your problem can be related to the way you pass the inputs to the Xero HTTP Request:
You trigger the HTTP Request with the output of your For block, but at this time, the “line_amount” input has not been defined as it needs to go through the evaluate block before.
I would probably try and pass all the data from the For block through the Evaluate, select the data you need from the Evaluate’s output as your input for your HTTP Request and also use the output as your Request’s trigger.
Hope it could help you a bit.
Hi, thanks for this. I did trigger the PUT request from the result of the Evaluate, however same result. I have a feeling it’s something to do with the repeat counter, as that is nested within for each company for loop… it does create some invoices, before the deadlock happens .. there are 3 companies to loop through and for each I’ve set the counter for the repeat to 2, so ideally each company has two invoices created for it.
Check out the logs ..it’s like the counter either isn’t incrementing or incrementing in an unexpected way .. wonder if the infamous @flows-daniel might know?
Hi @shazzaball
Welcome to the forums!
A couple things I see here:
- the repeat block within a triple loop generally runs into issues
- You’re using variables with a for loop, variables in flows are really constants today that are set once and use multiple times
I suggest removing the repeat block in favor of just duplicating your data before the first for loop, then collecting everything and flatterning the collected data into a standard list and looping through that to run your final Xero request. See below diagram for how it might look with a list placeholder instead of your initial request:
What I have in the first Evaluate block to duplicate data:
data.flatMap((item) =>
Array.from({ length: num }, () => item)
);
And in the second to flatten it:
const flatArray = [];
data.forEach(item =>
item.bodyList.forEach(bodyItem =>
flatArray.push({
name: item.name,
email: item.email,
id: bodyItem.id
})
)
);
flatArray
You’ll need to modify these slightly to fit your data structure. Postbot can be very helpful in doing this
This should get rid of your problems, let me know if you run into any more issues or I can help with anything else.
This is awesome - thank you @flows-daniel And I added in those Evaluate blocks instead. Everything is working much better, but I came across an odd thing thing today, and I just can’t see the issue. My For loop gets stuck on the first element and is highlighted in red, I can’t see any errors anywhere and the array looks ok … ? Am I missing something obvious?
Is it possible that the tenant_id isn’t being set?
If you try to run the flow without the variable (just use a placeholder) does it run correctly?
Ahhhh man .. I had been looking at this for too long and didn’t see that. I previously had to rebuild the flow under a different account as I had run out of ‘runs’, and didn’t create/refresh a new token to get the tenant_id. Sorted now and working like a dream. Thank you so much @flows-daniel