wvpv
3/9/2016 - 3:05 PM

SFMC-AMPScript-Coupon-Claiming.html

%%[

var @em, @couponRow,  @couponCode

if _messagecontext == "PREVIEW" then

    set @couponCode = "XX TEST XX"

else

    /* 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) 

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

endif

]%%

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