0

We have an email in prod that is for some reason not displaying some users their coupon code. In testing, I receive a code across multiple email clients. Email Ampscript is

%%[

SET @Salesforce_Id =  _subscriberkey
SET @dateassigned = NOW()
SET @couponrow_check = LookupOrderedRows('CouponbankDE',1,'Assigned_Date Desc','Salesforce_Id',@Salesforce_Id)

IF RowCount(@couponrow_check) > 0 THEN

    SET @Salesforce_Id_Check = Lookup('CouponbankDE','Salesforce_Id','CouponCode',Field(Row(@couponrow_check, 1) , 'CouponCode'))

ENDIF


IF _messagecontext != "VAWP" AND _messagecontext != "PREVIEW" AND @Salesforce_Id_Check != @Salesforce_Id THEN

    SET @CouponRow = ClaimRow('CouponbankDE', 'IsClaimed', 'Salesforce_Id', @Salesforce_Id, 'Assigned_Date', @dateassigned)

    IF NOT EMPTY(@CouponRow) THEN  
        SET @CouponCode = Field(@CouponRow, 'CouponCode')
    ENDIF

ELSE

    SET @couponrow1 = LookupOrderedRows('CouponbankDE',1,'Assigned_Date Desc','Salesforce_Id',@Salesforce_Id)

    IF RowCount(@couponrow1) > 0 THEN
        SET @CouponCode = Field(Row(@couponrow1, 1) , 'CouponCode')
    ENDIF

ENDIF
    
IF _messagecontext == "VAWP" THEN

    SET @couponrow1 = LookupOrderedRows('CouponbankDE',1,'Assigned_Date Desc','Salesforce_Id', @Salesforce_Id)

    IF RowCount(@couponrow1) > 0 THEN
        SET @CouponCode = Field(Row(@couponrow1, 1) , 'CouponCode')
    ENDIF

ENDIF

]%%
]%%
1
  • Please update your question to include the schema of CouponbankDE -- including field names, data types, primary key fields, etc. Commented Nov 5, 2021 at 13:45

1 Answer 1

0

Based on the multiple lookups in your question, I think you're misunderstanding how ClaimRow works.

If a coupon is already claimed for a particular subscriber, it'll return the one previously claimed instead of claiming another -- regardless of the message context -- just like a lookup. That is assuming your coupon DE is configured that way.

It could just be as simple as this:

%%[ 

if _messagecontext == "PREVIEW" then

    set @couponCode = "XX TEST XX"

else

    set @Salesforce_Id = AttributeValue("_subscriberkey")
    set @couponRow = ClaimRow("CouponBankDE", "IsClaimed", "Salesforce_Id", @Salesforce_Id)

    if not empty(@couponRow) then

      set @couponCode = Field(@couponRow, "CouponCode")

    else

        /* This aborts the entire send */
        RaiseError("No coupons available", false)

    endif

endif

]%%

You must log in to answer this question.

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