I use the same AMP-script to send individual coupon codes in several newsletters. Until now It always worked very well.

This is the AMP Script I use:

    %%[ /* COUPON VALIDITY */
VAR @CouponRow , @Coupon 
SET @CouponRow = ClaimRow('Geburtstagsgutscheine2021_ID', 'Used',"Email", @email) 
IF EMPTY(@CouponRow) THEN 
 SET @Coupon= "Sie haben schon einen Coupon bekommen." 
 SET @Coupon= FIELD(@CouponRow,'Geburtstags_Gutschein')

With this AMP-Script I claim a coupon code and while claiming it I write the claim date and the email of the customer who received the code into the coupon code data extension.

My problem is, that every time I want to claim a code, the email field in the first available row of the coupon code data extension stays empty. Nevertheless, at first glance it looks like the next rows in the coupon code data extension are claimed correctly.

But at second glance all customers receive receive the code from the row with the empty email field. Although their addresses claimed an own code in the coupon code data extension.

Does anybody of you have a suggestion for me on how to solve this problem?

Thank you for your help and best regards Jessica

1 Answer 1


There are multiple connected issues I think. It does get a bit dodgy overall so I would try and do the logic from scratch. See further below.

issue 1: First thing you do is claim a row, always. Then you check if it's empty. That will never happen:

"If a row is found and is unclaimed, the designated claimed column is set to true and data from that row is returned. If no unclaimed rows are available in the Data Extension, this function will return an error. " https://ampscript.guide/claimrow/

In other words, @couponRow it will never return "empty", if it were, the whole thing fails. You would need claimRowValue() to improve that.

So: I think everyone actually goes into ELSE, no one gets the message from IF.

Instead of using empty(), check for assigned rows in the context of, in your case, a person's email. Lookup is the function for that.

issue 2: The ELSE condition then does an incorrect lookup and returns the first instead of the correct voucher. I think that can be traced back that you do not ensure that the customer actually get's their assigned coupon.

issue 3(?): Also, ensure that @email is mapped to "the recipient's email", line 1. This isn't clear from your code. Try this pattern:

only if you do not find an assigned voucher, claim the next. ClaimRow should NOT be the first thing you do, but inside the ELSE condition.

SET @email = emailaddr
SET @previousClaim = Lookup("Geburtstagsgutscheine2021_ID","Geburtstags_Gutschein","Email",@email)
    IF not EMPTY(@previousClaim) THEN
        /* this person has a voucher assigned to their emailaddress. we just 
        looked it up, Let's just display that again: */
        SET @myCoupon = @previousClaim
       /* new person, NOW hand out a new voucher */
        SET @couponRow = ClaimRow('Geburtstagsgutscheine2021_ID', 'Used','Email', @email)
        SET @Coupon= FIELD(@CouponRow,'Geburtstags_Gutschein')

Hope this helps!

  • Thank you so much Jonas, it works perfectly! Jan 29, 2021 at 13:18
  • nice, please mark the answer as accepted :) Jan 29, 2021 at 13:41

You must log in to answer this question.

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