0

I am very new to ampscripting and I have inherited an ampscript for pulling promo code that was written by the previously developer that I couldn't make sense of. Here's the ampscript in question:

%%[var @em, @couponCode, @existingRow, @row, @couponDE 

set @em = AttributeValue("Email") 
set @existingRow = LookupRows("PromocodeDE","EmailAddress",@em)

if rowcount(@existingRow) > 0 then set @row = Row(@existingRow,1) 
    set @couponCode = field(@row,"CouponCode")

else if _messagecontext == "PREVIEW" then 
    set @couponCode = "XX TEST XX" 

else set @couponCode = ClaimRowValue("PromocodeDE", "CouponCode", "IsIssued","None Available","DateIssued",NOW(),"JobID",jobid,"ListID",ListID,"BatchID",_JobSubscriberBatchID,"SubscriberKey",_subscriberKey,"SubscriberID", SubscriberID,"EmailAddress",@em,"EmailName",emailname_) 

endif 
endif ]%% 

%%=v(@couponCode)=%%

I understand that ClaimRowValue should suffice for pulling of the promo codes and displaying it in the EDM. But I don't understand why there is a check before that to search the email address in the promo code DE.

Is this a common practice and what purpose does it serve?

1 Answer 1

0

This check is indeed normally not needed, as Claimrow function will return the row relevant for this subscriber based on the values provided in the Claimrow function. I.e. it will send the same coupon code to a recipient, if it can find a match in PromocodeDE. However, it will NOT find a match if you want the same code to be sent in multiple emails to the same recipient - as ClaimRow in this example passes a number of IDs which are unique to each send. So an email sent to me today, will provide a different coupon from the same PromocodeDE to one received yesterday. The check implemented here, which alone looks up the coupon based on the email address of the recipient, ensures these two code will be the same.

You can achieve same functionality by reducing the number of IDs passed in the Claimrow function to only SubscriberKey, rendering the initial check unnecessary:

%%[
var @couponCode 

if _messagecontext == "PREVIEW" then 
    set @couponCode = "XX TEST XX" 

else 
set @couponCode = ClaimRowValue("PromocodeDE", "CouponCode", "IsIssued","SubscriberKey",_subscriberKey) 

endif 
]%% 

%%=v(@couponCode)=%%

According to documentation, you sen set an arbitrary number of columns used for identification of the specific coupon code

You must log in to answer this question.

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