0

So I'm creating an email that needs to populate a coupon code from their email address.

The DE is called CouponCode

Field values are Email Address and Coupon.

The only information I have in the DE is Email Address and Coupon.

I thought I could get away with just declaring the coupon (%%coupon%%) and it'll find it automatically, but it didn't (I also tried %%=lookup(CouponCode,Coupon)=%% and that didn't work).

I'm not super familiar with AMPScript but I've used SQL queries before to pull info in the last platform I used. Is there a logic needed to populate the data? Do I need to link the DE to another DE/database to work? I'll be constantly adding new codes for different promotions, so that would be an extra step that I'd like to avoid. Also, some of these will be part of automated campaigns that will get replenished over time (though for right now it's for a one-off).

1

You've got to establish the lookup parameters in order to retrieve the coupon codes. The emailaddr is a personalization string present in all email sends.

%%[

var @couponCode, @emailAddr
set @emailAddr = AttributeValue("emailaddr")
set @couponCode = Lookup("Coupons", "CouponCode", "EmailAddress", @emailAddr)

]%%
CouponCode: %%=v(@couponCode)=%%

Reference

5
  • Thanks! Does it matter where in the HTML the query is placed? In the code to display the variable, I only put in '%%=v(@couponCode)=%%' not 'CouponCode: %%=v(@couponCode)=%%' (guessing that's just explaining what that is...)? Example: <p>Use Coupon Code:<b>%%=v(@couponCode)=%%</b></p>
    – Joeshmo
    Dec 6 '16 at 15:58
  • The %%=v(@couponCode)=%% can be anywhere in your HTML as long as it's after the %%[ ]%% AMPScript block Dec 6 '16 at 16:47
  • Thanks, though I did see an error in that the order in the Lookup was wrong (its sequential order: DE --> Row/Column). CouponCode should be before Coupons. Otherwise this was perfect. Thanks!
    – Joeshmo
    Dec 8 '16 at 15:30
  • Sure about that? The first parameter (according to the documentation) is Name of data extension from which to return specified value. The second is Name of column from which to return value. Dec 8 '16 at 15:34
  • Yeah, that's what I meant. Think the example had it flipped by accident ('CouponCode' was the DE the way I had it)
    – Joeshmo
    Dec 8 '16 at 21:15
-2

just look for the presence of the coupon column in some list attribute with same name because if it does, then the precedence will take list attribute first and that being blank will display nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.