0

I have created an email with SFMK with coupons.

This is:

%%[
var @couponRow,  @couponCode , 

set @email = AttributeValue("Email Address")
set @FirstName = AttributeValue("First Name")
set @LastName = AttributeValue("Last Name")
set @AssetNumber = AttributeValue("Asset Number")

set @couponRow = ClaimRow('Data_Extension_Code','IsClaimed', 'Email Address', @email, 'First Name', @FirstName, 'Last Name', @LastName, 'Asset Number', @AssetNumber)

if empty(@couponRow) then
RaiseError('No coupons available', false)
else
SET @couponCode = Field(@couponRow,'CouponCode')
endif
]%%

But I need that if there are no coupons available that the coupon is not shown, how can I do it.

Because all costumers receive that email but not all have a coupon.

Thanks.

2
  • Is this a bulk scheduled or adhoc send or is it a journey/trigger/transactional send? What are your thoughts on pre-assignment? Commented Jan 15, 2021 at 15:50
  • It's a journey send.
    – Mery
    Commented Jan 18, 2021 at 9:39

1 Answer 1

0

You want to update the IF statement to show alternative content, and not raise an error. If an error is raised, the email is not sent.

%%[

set @email = AttributeValue("Email Address")
set @FirstName = AttributeValue("First Name")
set @LastName = AttributeValue("Last Name")
set @AssetNumber = AttributeValue("Asset Number")
SET @Eligible = AttributeValue("Eligible")

IF @Eligible == "true" THEN
set @couponRow = ClaimRow('Data_Extension_Code','IsClaimed', 'Email Address', @email, 'First Name', @FirstName, 'Last Name', @LastName, 'Asset Number', @AssetNumber)

ENDIF

if @Eligible == "false" then
]%%

You shall not receive any codes today!

%%[
ELSE IF (@Eligible == "true" AND NOT empty(@couponRow)) THEN
]%%

Your code is %%=Field(@couponRow,'CouponCode')=%%

%%[
ELSE
RaiseError('No coupons available', false)
endif
]%%

Above code will allow you to send emails, even though no unclaimed rows are available. However, based on your statement: Because all costumers receive that email but not all have a coupon. You also need to add another level of logic to your email, as you need to claim rows only for recipients who are eligible to receive the code. So, if you assume a field Eligible on the sendable data extension, you can check this, an only claim if the recipient is eligible for the code.

If your recipient IS eligible, but you have run out of codes, you can use RaiseError to prevent the email from being sent. But all this depends of course on what type of business logic you want to implement.

3
  • Thank you. But I need that all customers received this email, it's possible to hide the content of the codes for those customers.
    – Mery
    Commented Jan 15, 2021 at 13:28
  • @Marina - I don't understand this use case. Keep in mind, that you might face a scenario where there are no more available codes in the data extension. So in cases where the recipient is entitled to receive a voucher code, we can't provide one to him. Would you like to send same content as you would to recipients not entitled to a voucher code? Commented Jan 15, 2021 at 15:15
  • Yes, I will follow your advice. If I don't have a code, i wont send an email, until new codes will be available. Thank you.
    – Mery
    Commented Jan 15, 2021 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .