[SalesForce] Creating a simple AMPScript to retrieve value from DE

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).

Best Answer

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

Related Topic