I am using the script and modified it to my needs:

/*Sets de AB */ 
set @modtarget = AttributeValue("_customObjectKey")

if not empty(@modtarget) then 

  if mod(@modtarget, 2) == 0 then  /* even */
    set @randomAB = "1"
  else /* oneven */
    set @randomAB = "2"


In my sendlog the field randomAB exists. I am using this so I can query the sendlog with data views. It works but ofcourse every record will be stored with 1 or 2 in the randomAB field within the sendlog even when I am not using it in an AB test. Is there a way to only add the 1 or 2 to a specific piece so that not every email results in a 1 or 2. For example:

I have a dynamic title in my email. There are, lets say, 10 different titles. Based on the data you will got one of these titles. I want to AB test title 1. So only the records that are using version 1 or 2 of title 1 should be stored with 1 or 2 in the randomAB field within the sendlog. The default of randomAB in the sendlog is set to 0. So every record that has title 2-10 should be stored with 0 in the sendlog (hopefully this make sense). Is this possible?

2 Answers 2


You could calculate the test case using the _customObjectKey -- the hidden identity number associated with the row in the data extension. This key value would would remain associated with the send to a specific subscriber as long as the data extension is not overwritten.

If the result of the modulo operation is even, use subject #1; if odd, use subject #2:


set @ck = AttributeValue("_customObjectKey")

set @subject = "default"

if not empty(@ck) then 

  if mod(@ck, 2) == 0 then  /* even */
    set @subject = "subject 1"
  else /* odd */
    set @subject = "subject 2"




  • Works like a charm. Noticed one thing. When I select a data extention with records created manually it doesn't work. If I select a data extension that is pupulated via a import it works fine. Is my conclusion correct that the _customObjectKey only exists when data is imported via a import or API injection?
    – Martijn e
    May 24, 2023 at 12:34
  • I haven't encountered missing _customObjectKey values. You should be able to verify with a retrieve of a DataExtensionObject (aka row) via SOAP API or WSProxy. May 24, 2023 at 15:20

I fixed it. In the script I target directly the field in the sendlog. I changed the field randomAB in the script to something else and use that for targetting the right title. In the ampscript of the titles I added the randomAB field so it only writes 1 or 2 when the subjectline is targetting.

You must log in to answer this question.

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