I am building an email journey for 10% off when you sign up on an online shop. I have 1 DE with the contacts email address, name and subscriber key and another with the unique 10% off code - which have been created in the Ecom CMS and loaded in a separate DE. These can only be used once and are unique for each user.

However the joining of these are only done in the email and no where else. So far I have the DE as the entry source but in the email I have chosen the other DE when creating the Dynamic Block content. However it is not validating the journey.

Is this at all possible? If so how do I get the code to change on each send? I am guessing this will only be done through AMPscript?

Thanks in advance!

  • What fields are in your discount code DE? Is each code assigned to a particular user? Apr 15, 2021 at 15:39
  • it just has codes in there and not assigned to any particular user. There are about 1 million unique one-time only codes.
    – Sabah
    Apr 15, 2021 at 16:08

1 Answer 1


Given what you've described, it would be worth looking at this guide to claiming coupon codes by the excellent Adam Spriggs: https://sprignaturemoves.com/coupon-claiming-in-ampscript/

This utilises the ClaimRow function in AMPscript.

You'll need a data extension where the field for your coupon/discount code is the primary key (you presumably already have this). You need two extra nullable fields - IsClaimed (this should be boolean, with a default value of False) and EmailAddress (or SubscriberKey if you want to associate with Subscriber Keys - you'll need to update the AMPscript accordingly if so).

Then, here's the AMPscript Adam provides:


var @em, @couponRow,  @couponCode

if _messagecontext == "PREVIEW" then

    set @couponCode = "XX TEST XX"


    /* include your sendable attribute/column here */
    set @em = AttributeValue("emailAddr") 

    set @couponRow = ClaimRow("CouponsCodes", "IsClaimed", "EmailAddress", @em)

    if empty(@couponRow) then

        /* You can do other error handling here if you want.*/
        /* This aborts the send */    
        RaiseError("No coupons available", false) 

        SET @couponCode = Field(@couponRow, "CouponCode")



You can then print the retrieved value in your email:

Here's your coupon code: %%=v(@couponCode)=%%

When a code is claimed, the IsClaimed field in your Codes data extension will be marked as True and the EmailAddress or SubscriberKey column (depending on what you choose to use) will be populated with the relevant value for the subscriber that claimed the code.


If you're putting this in an automated campaign/journey, you should also think about setting up alerts when you're close to having no codes left, so you know to replenish the codes DE.

  • Hi Antonio. You should preferably place the code within your answer, in addition to referring to Adam's post. In case the URL changes, there will be no way of finding the source of the solution in the future. Apr 16, 2021 at 7:44
  • Thanks @LukasLunow - good point. I've updated the answer accordingly. Apr 16, 2021 at 10:19

You must log in to answer this question.

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