I'm looking to take the value of an AMPscript function - like Random() - and lock that result so any future references to that variable, beyond the initial email send, reflect logic processed against the same value as at time of send. I'm looking to use Random() to drive A/B testing in triggered sends, but the issue that I can't solve is that the Random() function is running both at time of send and at any point thereafter where someone uses the VAWP link, with potentially inconsistent results.

As an alternative use case, I also have content that changes relative to the date. I am using the send log to store the VAWP link so that support staff can see the content of these emails that were sent to customers, however whenever they visit the link, the AMPscript re-processes using the current date rather than the date from the time of send. Ideally, I want the VAWP to reflect the content that was rendered at time of send.

Any thoughts on the best way to accomplish this?

1 Answer 1


Your best bet is to have a field for these inside of your data extension and then reference those fields beyond the first rendering.

Easiest way to do this:

  1. Create 2 nullable fields in your DE (Random | SentDate)
  2. Leave these fields blank for initial send
  3. Inside your email use the following AMPScript:

    SET @Random = LOOKUP(@yourDE, "Random", "SubscriberKey",  _subscriberkey)
    SET @SentDate = LOOKUP(@yourDE, "SentDate", "SubscriberKey", _subscriberkey)
    IF EMPTY(@Random) THEN
       SET @Random = RANDOM()
       UPSERTDE(@yourDE, 1, "SubscriberKey", _subscriberkey, "Random", @Random)
    IF EMPTY(@SentDate) THEN
       SET @SentDate = NOW()
       UPSERTDE(@yourDE, 1, "SubscriberKey", _subscriberkey, "SentDate", @SentDate)
  4. Profit

This should make it so that the first run through does the RANDOM() and NOW() functions to assign the correct values and then UPSERT these values into the Data Extension. This way any future views of this send will display the send time values that were assigned.

You must log in to answer this question.

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