I have a pretty straightforward workflow, but had a question on how to handle multiple steps within a loop.
Retrieve all new records to process.
For EACH of these new records, I need to do multiple things:
Generate QR Code (Loop 1)
Send email (Loop 2)
Update database indicating email has been sent. (Loop 3)
I have the workflow working for a basic case, but when I started to throw in error scenarios (for example, a bad email address), then the 3rd loop fails to execute.
I feel like my design is wrong and I should have 1 loop that does 3 things - but I wasn't able to figure out how to set up the workflow that way. Can someone help a workflow newbie? Is the way I have it correct? How do I handle an error scenario when using the Retool Email. I have "finally" configured to "continue" on that step by the way.
I need to generate a QR code to attach to the email. I have this as a loop step before the email loop step. It would make more sense to call the QR code generation from within the email loop step, but I was not able to figure out how to do this. This seems like there may be a case where QR code generation failed for a certain row, and now I am sending the wrong QR code to people because the data is off by 1.
Your intuition is right, I would not set it up this way - with three loops in a row based off the same dataset where each subsequent loop is predicated by the success/failure per record of the previous step, it seems you would need to track all that and mutate the data before proceeding to the next step which is too much work.
I would run your newTickets query, and then for Step 2, I would loop through the results and for each record I would call another workflow (passing the json parameters you need in the body). The other workflow, I'll call it doStuff, receives the parameters you pass in as its startTrigger.data, and from there, within doStuff, you fire off your 3 resource queries (qr, email, update db) in a row. doStuff is deployed but doesn't have any actual triggers like timer etc, it just sits there waiting to be called. You could build error handling into both main workflow and doStuff (send email for failure, or update log file in db etc.)
The way you're getting your QR in its own query before email is fine, and by putting it in the doStuff you're only dealing with one record at a time so it can't be mixed up anymore.
Now, having said all that, and being relatively confident that's how it's designed to work, I'll admit I'm having issues with my own similar scenario. I'm having way too many timing related errors within my doStuff because (I think) the main workflow loop is executing too fast. I may start my own thread. Hopefully others can chime in and fix us both.
I hope this below will give you idea how to proceed. This solution utilized functions to make the call to your operations. Also JS Promise is heavy used here.
Note: the example used simple SQL as illustration but the concept is what convey here.
In image below:
Functions are what make the call to your SQL/API
the loops make to call and utilize promise to get the results.
The loops return json object for each item...passing back any data as needed and the status of performed in this the current loop.
Second loop, check the status performed in previous and proceed if success.
Hi all! Excited to share that we now support multi-step functions in Workflows, which you can utilize to set up nested loops. Check out this loom of @Jessica_D's use case applied to nested loops!
Multi-step functions are currently in beta -- please reach out to me at lizzie@retool.com with your organization's subdomain if you'd like to try it out!