2 weeks ago
Hello,
I'm working on a recipe in which I am pulling a list of customer outstanding invoices from a SQL table. I can get the data from the SQL and create a list, but I want to be able to loop through that list and create a table/list of invoices for each customer who have more than one outstanding invoice and send one email showing that table listing all of their overdue invoices rather than sending multiple emails for each overdue invoice. Would really appreciate some help with this.
2 weeks ago
If you have a list of all invoices, you can make a unique array of all customers. Then you want to loop on the array of customers first, and within that loop you want another loop for all of the invoices. You can then aggregate all customer-specific invoices by checking if the current customer value (outer loop) is the same as the invoice customer (inner loop). Once you have the customer-specific invoices aggregated in isolation from all invoices, you can process them however you'd like.
The "loop in a loop" may be frowned upon, but in this case you won't burn through a lot of tasks because your customer==customer conditional is narrowing down which invoices get processed. There are definitely other ways to do this that may have less task usage, but I think this approach keeps the recipe simple. Simplicity is a fair trade for a few extra tasks.