In this article, we’ll show how to set up an automation flow that notifies users about an unused coupon we’ve sent them.
Coupon Preparation
Coupons we need for our flow must be in a single group, for example:

Preparing templates
We need to create two templates. The first template will be for sending a coupon from a group and the second will be for displaying an unused coupon we’ve already sent and stored. For example:


The template on the left loads a coupon from the specified group. (Learn more about working with discount coupons here)
The template on the right loads the coupon, which we’ll save using a custom block. We’ll show that in the next section.
Preparing automation
First, add a custom block and paste this code into it:
{{
usedCoupon = loadLastUsedCoupon 270 // ID of coupon group
if (usedCoupon == null || usedCoupon.applied != null)
setFinishedState
end
result = saveData 'usedCoupon' usedCoupon
}}
The code retrieves the last coupon sent for the given user, checks whether it has been used, and stores it in a variable named usedCoupon. Learn more about the custom programmable block here.
Automation progress
Lastly, we need to prepare the automation flow, which might look like this:

This workflow selects users from the recipient list who are celebrating their name day. It sends them a discount coupon, waits a few days, and then checks whether the coupon was used. If not, it saves the coupon. If the user still didn’t use the coupon, the second template we created is sent — it applies the saved coupon and inserts it into the template.
For the automation to work correctly, the element Send email must be set to Send to recipient. The coupon is tied to the recipient’s email. If the email were sent to the operator, the data would be mismatched and an error would occur.
Adam Koutný