1

I have an email in a journey that is using the ClaimRow AMPscript function to send unique vouchers.

The ClaimRow function is included into an "If Statement", and repeated multiple times, so that we can claim vouchers from different data extensions depending on a condition. The code looks like this:

IF @VoucherType == 'A' THEN
        SET @CouponCodeRow = ClaimRow('DataExtension_A','IsClaimed','ClaimedBy',@SubscriberKey)
        SET @CouponCode = field(@CouponCodeRow,'CouponCode')
        UpdateDE('DataExtension_A',1,'CouponCode',@CouponCode,'ClaimedBy',@ClaimedBy)
    
ELSEIF @VoucherType == 'B' THEN
        SET @CouponCodeRow = ClaimRow('DataExtension_B,'IsClaimed','ClaimedBy',@SubscriberKey)
        SET @CouponCode = field(@CouponCodeRow,'CouponCode')
        UpdateDE('DataExtension_B',1,'CouponCode',@CouponCode,'ClaimedBy',@ClaimedBy)
    
ELSEIF @VoucherType == 'C' THEN
        SET @CouponCodeRow = ClaimRow('DataExtension_C','IsClaimed','ClaimedBy',@SubscriberKey)
          SET @CouponCode = field(@CouponCodeRow,'CouponCode')
        UpdateDE('DataExtension_C',1,'CouponCode',@CouponCode,'ClaimedBy',@ClaimedBy)
ELSE
        RaiseError ('xxx', true)
ENDIF

The code works as expected and claims the voucher from the proper DE, however, it ALSO claims a voucher from the last data extension included in the IF statement (in my example it would be "DataExtension_C"), so 2 rows are claimed every time an email is sent.

Following my example, when the VoucherType is 'A', a row is claimed from the "DataExtension_A" and the voucher is shown in the email, but another row is claimed from "DataExtension_C". A voucher from "DataExtension_C" is always claimed, no matter what the conditions.

The voucher from the "DataExtension_C" is not sent to the subscriber, but it appears as 'claimed' in the data extension, so we're consuming a significant amount of vouchers.

No idea what's going on here! Has anyone seen this before?

2 Answers 2

3

**** EDIT **** I found your issue, you are missing a end quote on your first elseif statement. You never closed the quote to set the data extension in your ClaimRow in the ELSEIF for B.

Current:

ELSEIF @VoucherType == 'B' THEN
        SET @CouponCodeRow = ClaimRow('DataExtension_B,'IsClaimed','ClaimedBy',@SubscriberKey)

Corrected:

ELSEIF @VoucherType == 'B' THEN
        SET @CouponCodeRow = ClaimRow('DataExtension_B','IsClaimed','ClaimedBy',@SubscriberKey)

This then caused the unexpected behavior due to the syntax issue and likely is the reason for the double claim.


I have run into this when the prebuild process is implemented on sends. See this article for details on the issue.

Essentially it is saying that if you use a variable in an if statement that pulls from a relational data extension, then it can cause some unexpected behaviors with claimrow and insert/upsert type functions. This is because PreBuild will run through the email and process all the AMPscript minus the data reliant aspects. This then allows the majority of the email be ready to be sent out at a much higher throughput as it is mostly already built before it hits send queue. The issue there though is that it will be 'processed' twice and with different variable values if it is pulled from DE.

The fact that it is hitting 'C' variable each time worries me some that above is a 1:1 match, as usually it will default to running the 'Else' not a specific 'Elseif' so I would also investigate your surrounding AMPscript and see if there is potentially some syntax issue (missing comma, paranthesis, ENDIF, etc...) that is breaking the condition or expected outputs.

5
  • Hi @Gortonington. Thank you very much for your feedaback. Unfortunately we're not using the prebuild process so I still don't know why the issue is happening
    – Gio
    Jun 26 at 10:24
  • @Gio - have you checked the rest of the surrounding AMPscript to see if potentially there is a syntax issue or similar somewhere else that is causing unexpected behavior on this IF statement? Also I would validate how @VoucherType is being set. Also, Text version and HTML version in Multi-MIME type run through the AMPscript separately, so there is a potential for the dual claiming there as well. Jun 26 at 13:14
  • Hi @Gortonington . Yes, I've checked the surrounding AMPscript and I also asked some colleagues to check it and no one of us has encountered any error in the syntax. In addition, I've created a simple journey with the same email and I didn't face the issue (having Multi-MIME enabled as well). So I'm not able to reproduce the error, but for some reason It happens in the live journey.
    – Gio
    Jun 27 at 13:41
  • If you check out my edit on my answer @Gio, I found the likely issue which was a missing quote in the first elseif. Jun 27 at 15:30
  • Thanks a lot @Gortonington, however, that mistake is not in the code. When I posted the question, I changed the names of the data extensions to generic names and I forgot to add the end quote in the ELSEIF for B.
    – Gio
    Jul 3 at 8:18
0

Could try to piggyback of this solution: using variable for ampscript Claimrow function

IF @VoucherType == 'A' THEN
        Set @couponDE = "DataExtension_A"
ELSEIF @VoucherType == 'B' THEN
        Set @couponDE = "DataExtension_B"
ELSEIF @VoucherType == 'C' THEN
        Set @couponDE = "DataExtension_C"
ELSE
        RaiseError ('No voucher for you!', true)
ENDIF
    
TreatAsContent(Concat("%%[ SET @CouponCodeRow = ClaimRow('", @couponDE, "', 'IsClaimed','ClaimedBy', '", @SubscriberKey, "') ]%%"))
    SET @CouponCode = field(@CouponCodeRow,'CouponCode')
1
  • 1
    If the issue is related to the PreBuild issue I shared in my answer, this would run into the same issue that is currently happening. Jun 20 at 19:34

You must log in to answer this question.

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