ClaimRowValue

Like the ClaimRow function, ClaimRowValue returns a single row from a Data Extension and reserves the values to prevent them from being used by another operation. If a row is found and is unclaimed, the designated claimed column is set to true and data from that row is returned. Unlike ClaimRow, if no unclaimed rows are available in the Data Extension, this function will return the value specified in the fourth parameter. Claimed rows can be used again if the designated claimed column changes back to false.

Generally speaking, you might choose to use the ClaimRowValue function over the ClaimRow function when you have a default value that can be presented to your Subscribers.

To utilize the ClaimRowValue function, you will need a Data Extension with some specific characteristics. At a minimum, your Data Extension must include the following:

  1. a Boolean column that indicates claimed status, where true is claimed and false is unclaimed
  2. a nullable column that represents the object or recipient claiming the row.

TIP: You can also utilize the ClaimRowValue function in an SMS campaign.

TIP: Ensure you upload sufficient coupon codes for your entire target audience. For recurring coupon campaigns, it’s a good idea to have some method of monitoring unused coupon codes.

TIP: Ensure the target of the coupon code (e-commerce site, point-of-sale or POS system etc.) is using the same set of coupon codes as your campaign.

TIP: If you include a column named ClaimedDate in your Data Extension, the ClaimRowValue function will automatically populate it with the current date and time when a row is claimed.

Arguments

ClaimRowValue(1,2,3,4,5,6,[7a,7b]...)

Ordinal Type Required Description
1 String True Data Extension from which to retrieve rows
2 String True Name of the column from which to retrieve the value
3 String True Name of the column that identifies a row as claimed
4 String False Default value to use if there are no available rows to claim
5 String True Name of the Data Extension key column
6 String True Value of the Data Extension key column
7a String False Additional name of the Data Extension key column (see note)
7b String False Additional value of the Data Extension key column (see note)

NOTE: Additional pairs of columns and values can be appended as arguments.

NOTE: The Data Extension name in the ClaimRowValue function cannot be an AMPscript variable.

Example 1

The following illustrates the use of this function with the minimum number of arguments.

A sample Data Extension schema for the ClaimRowValue example is provided below.

Data Extension: CouponCodes

Name Data Type Length Primary Key Nullable Default Value
CouponCode Text 50 Y N
IsClaimed Boolean N Y False
EmailAddress EmailAddress N Y
ClaimedDate Date N Y

The CouponCodes Data Extension could include these initial rows:

CouponCode IsClaimed EmailAddress ClaimedDate
SJOCYUNGIX False
ZURRPSIDQD False
LFZCWGPFCS False
KTZUYGCFOZ False
WDQHIUBVFS False

In this example, checking the _messageContext personalization string allows the coupon codes to be preserved while testing the AMPscript function.

%%[

var @em, @defaultCoupon

set @defaultCoupon = "SAVE30"

if _messagecontext == "PREVIEW" then

    set @couponCode = "XX TEST XX"

else

    /* include the send context attributes or columns to record here */
    set @em = AttributeValue("emailAddr")

    set @couponCode = ClaimRowValue("CouponCodes", "CouponCode", "IsClaimed", @defaultCoupon, "EmailAddress", @em)

endif

]%%

Coupon code: %%=v(@couponCode)=%%

Output

If the AMPscript code referenced previously was executed in an email send to a single Subscriber, [email protected], the following would appear in the email:

Use this coupon code: SJOCYUNGIX

The result of the ClaimRowValue function would result in this claimed row in the CouponCodes Data Extension:

CouponCode IsClaimed EmailAddress ClaimedDate
SJOCYUNGIX True [email protected] 2017-10-10 12:34
ZURRPSIDQD False
LFZCWGPFCS False
KTZUYGCFOZ False
WDQHIUBVFS False

If the same code is used and there were no available coupons for claiming, then the function would return the default value specified in the fourth parameter:

Use this coupon code: SAVE30

Example 2


Not a subscriber? Subscribe now.