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:
- a Boolean column that indicates claimed status, where
true
is claimed andfalse
is unclaimed - a nullable column that represents the object or recipient claiming the row.
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 | Boolean | 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 | False | Name of the Data Extension column to populate |
6 | String | False | Value of the Data Extension column to populate |
7a | String | False | Additional name of the Data Extension column to populate (see note) |
7b | String | False | Additional value of the Data Extension column to populate (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.
NOTE: By default, this function does not support primary keys like the other update and upsert Data Extension functions. Additional name/value pairs of arguments are only for recording additional information at the time the row is claimed, not for retrieving coupons using additional values. Marketing Cloud Support may be able to alter this default behavior by adding explicit indexes to your coupon data extension, per this documentation.
Not a subscriber? Subscribe now.
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, doug@limedash.com
, 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 | doug@limedash.com | 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.