How to get the lambda to fire only if a function is true

Got to say,
The docs for the loop/lambda are NOT great - needs more explanation/examples.

I have a loop (query4) iterating through my dataset, and I want to fire the lambda and trigger an email for each item in the dataset ONLY if a called function is true -
I'm firing the query4_lambda.trigger() on each iteration and trying to call the function each time but it doesnt seem to work.

The idea is ONLY to send an email if the return from the called function (triggered by the lambda iteration..) is true.
Example: I have 5 items in my dataset (2 of them should be true) so it should fire the lambda on each of the 5 iterations, and then only trigger an email if the called function is true - should occur twice when iterating through the dataset.

Hi @peter.b,

Can you share a screenshot of your code?

It sounds like you're trying to do 2 things inside the loop, but I'm unclear if the loop function query4 is the one that sends the email, or checks if it should send the email.

While definitely possible to do it all at once, it might be cleaner to have 2 loops, or a filter step, before you send the emails. Something like:

// Input data "mainData"
 { email: "", send: true},
 { email: "", send: false},
 { email: "", send: true},
// Filter Block
// this will only return the 2 objects that have "send" set to true
return => item.send === true)

Then use the output of the Filter Block in your loop, so it's only looping over the ones that should be sent.

I ended up doing what I needed to do directly in js code