[SalesForce] using variable for ampscript Claimrow function

I plan to use many data extensions for voucher code
so I created a reference data extension and capture the data extension name from there

SET @getde = Lookup ("v1-reference", "DE", "date_code", @fullcode)

and then I claim the row

 SET @voucherrow = ClaimRow(@getde, "IsClaimed", "email", email)

but this will create an error
I've tried to put the data extension name directly in the function and it works:

SET @voucherrow = ClaimRow("voucher_pool", "IsClaimed", "email", email)

Is there any of you know how to achieve this, a workaround maybe. Thanks

here is the error:

Best Answer

I made it work this way:

    %%[
    SET @SubscriberKey = 'My_SubscriberKey'
    SET @de_name = 'My_DE_Name'
    TreatAsContent(Concat("%%[ SET @CouponRow = ClaimRow('", @de_name, "', 'IsClaimed', 'JobID', JobID, 'ListID', ListID, 'BatchID', _JobSubscriberBatchID, 'SubscriberKey', '", @SubscriberKey, "') ]%%"))

    IF NOT EMPTY(@CouponRow) THEN
    ]%%
    Your Coupon Code is %%=Field(@CouponRow,'CouponCode')=%%
    %%[ ENDIF ]%%

TreatAsContent will execute the code string and set the @CouponRow for later use.

I sometimes had an issue with the code erroring but I fixed it by closing and re-opening the AMPScript block tags around the TreatAsContent this way:

    ...
    ]%%
    %%[
    TreatAsContent(Concat("%%[ SET @CouponRow = ClaimRow('", @de_name, "', 'IsClaimed', 'JobID', JobID, 'ListID', ListID, 'BatchID', _JobSubscriberBatchID, 'SubscriberKey', '", @SubscriberKey, "') ]%%"))
    ]%%
    %%[
    ...
Related Topic