0

I am using the following code in order to retrieve a coupon from a Data Extension, but I have an issue. When I sent an email to several contacts, they received the same coupon. Could you tell why this code doesn't work correctly?

set @rows = LookupRows("CouponCodes","Country", @countrycode, "IsClaimed", "False")

if rowcount(@rows) > 0 then
  set @row = Row(@rows,1) 
  set @couponCode = field(@row,"Code")
else

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

  set @couponRow = ClaimRow("CouponCodes","IsClaimed","Contact_ID", @Contact_ID) 

  if empty(@couponRow) then
     /* You can do other error handling here if you want.*/
     /* This aborts the send */
     raiseError("no more coupons available")
  else 
     set @couponCode = field(@couponRow,"Code") 
     UpdateDE("CouponCodes",1,"Code", @couponCode,"Contact_ID", @Contact_ID)
  endif

endif 

endif
  • looks like it was copy pasted and "slightly" modified. did you write this code? – glls Nov 23 '17 at 1:27
0

With this:

set @row = Row(@rows,1) 

You are selecting the first row if there is any coupon code for that country.

I think you need a for loop, something like that:

if rowcount(@rows) > 0 then

 FOR @i = 1 TO rowcount(@rows) DO   
    set @row = Row(@rows,@i)
    set @couponCode = field(@row,"Code")

You can use different coupon codes like that.

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.