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
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:
- a Boolean column that indicates claimed status, where
trueis claimed and
- 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
ClaimedDatein your Data Extension, the ClaimRowValue function will automatically populate it with the current date and time when a row is claimed.
|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.
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|
The CouponCodes Data Extension could include these initial rows:
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)=%%
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:
|SJOCYUNGIX||True||[email protected]||2017-10-10 12:34|
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