---
schema_version: "1"
id: 142e868659d341cbd316cb8914fac341ccd6f544280f0b5459bc143c9ab029ed
title: Display Send-Time Content Contextually
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/guide/examples/mc-ampscript-examples-send-time-content.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/guide/mc-ampscript-examples-send-time-content.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4d091b30a03df61c56264ee5270caeb43373cc248c81ea9448ad6dd71e6a6c88
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# Display Send-Time Content Contextually

You can use AMPscript to pull information from a send logging database to determine which content displays to your subscribers. Depending on the context of the displayed content, you can use a send logging database to pull different information for those contexts. For example, you can display the content current as of send time as shared Social Forward content or content viewed on a web page. You can also display the most recent content when that content is displayed in an email message.

This example shows you how to pull send-time content from a data extension so that you can use the data in your chosen context.

## Prerequisites

To use this example, the send logging feature must be enabled for your account. For more information about enabling this feature, contact your Salesforce Account Executive.

## Basic Code Example

This code example pulls send-time data from a send logging data extension when the content is viewed in an email. For shared content or content viewed in a web page, the AMPscript displays the most current content.

The first block of the code sets up the variables necessary to contain the appropriate data and hold the applicable `SubscriberID` and `JobID` values. The `@SendLogData` lookup call references the send logging data extension and retrieves the information in the field assigned to the specific subscriber and job. The If-Else statement displays the content from the send logging data extension if that content resides in a web page or in a Social Forward context. Otherwise, the AMPscript displays the email content.

```AMPscript
%%[
  /* Set variables for looking up in send logging data extension. */
  Var @SendLogData, @SubLookup, @JobLookup
  Set @SubLookup = SubscriberID
  Set @JobLookup = JobID
  Set @SendLogData = Lookup("Send_logging_DE","DE_Field","SubID",@SubLookup,"JobID",@JobLookup)

  /* Determine what should be displayed based on how the email is viewed. */
  If _MessageContext == "VAWP" or _MessageContext == "Social" or _MessageContext == "FTAF" then
]%%

/* Content to display when using the view as a web page, social forward, or forward to a friend features */
send logging value: %%=v(@SendLogData)=%%

%%[ Else ]%%

/* Content to display in the email inbox */
email value: %%DE_Field%%

%%[ EndIf ]%%
```

## Code Example with BatchId and Send Logging

If you send the same email message more than one time, the “View As A Web Page” option can reference an earlier version of the email message that doesn’t reflect subsequent changes. To avoid this situation, reference the BatchID of the send in your AMPscript code to ensure that the correct email message is displayed as a web page. The user-defined `@eventID` variable either references the current send or an earlier version using the “View As A Web Page” option.

If you send the same email message more than one time and use the “View As A Web Page” option, we recommend that you use send logging. If you don’t use send logging and a recipient is removed from the data extension before the next send, their “View As A Web Page” link stops working.

```AMPscript
%%[
  Var @eventId, @emailaddr, @SendLogEID, @SendLogEM, @SubLookup, @JobLookup,@BatchLookup
  Set @SubLookup = SubscriberID
  Set @JobLookup = JobID
  Set @BatchLookup = _JobSubscriberBatchID
  Set @SendLogEID = Lookup("SendLog","EventID","SubID",@SubLookup,"JobID",@JobLookup,"BatchID",@BatchLookup)
  Set @SendLogEM = Lookup("SendLog","EmailAddress","SubID",@SubLookup,"JobID",@JobLookup,"BatchID",@BatchLookup)

  If _MessageContext == "VAWP" or _MessageContext == "Social" or _MessageContext == "FTAF" then
    Set @eventId = @SendLogEID
    Set @emailAddress = @SendLogEM
  Else
    Set @eventId = [EventID]
    Set @emailAddress = [emailAddress]
  EndIf
]%%
```

## See Also

- [Lookup()](/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-data-extension/mc-ampscript-reference-data-extension-lookup.html) function reference
- [Send Logging in Email Studio](https://help.salesforce.com/s/articleView?id=mktg.mc_es_send_logging.htm)
