You are here:
Use Marketing Object Data in Messages
To include data from marketing objects in your messages, use AMPscript or Handlebars code. You can include AMPscript and Handlebars in messages that you create by using the visual editor, or messages you create by using the API.
Required Editions
| Salesforce Enterprise and Unlimited Editions with Marketing Cloud Next Growth or Advanced Edition |
Field Identifiers
Each marketing object has a unique identifier, which consists of the API name for the
object followed by __mo. For example, if the API name of a marketing object
is CustomerRewardMembers, the unique identifier for the marketing object is
CustomerRewardMembers__mo.
The fields in the marketing object have identifiers that end with __c. For
example, if the API name for a field in a marketing object is
RewardsPoints, the identifier for the field is
RewardsPoints__c.
Use these identifiers with the AMPscript Lookup() function or the Handlebars QueryFirst helper to retrieve data from a marketing object.
Data Graph Data
You can also retrieve fields from the data graph for your account. A data graph contains
attributes that you can use to personalize your messages. Each Marketing Cloud Next account
or business unit has a default data graph. The identifier for a data graph field is
$dataGraph. followed by the field name. For example, to reference the
Email field in your data graph, use $dataGraph.Email__c.
For more information about data graphs in Marketing Cloud Next, see Set Up Personalization
Features in Marketing Cloud Next.
Usage Example
As an example, assume that you have a marketing object called CustomerRewardMembers, which contains the data in this table:
| FirstName | LastName | EmailAddress | RewardsPoints |
|---|---|---|---|
| Sarah | Johnson | johnsonsarah@example.com | 1250 |
| Michael | Chen | michael.chen@example.com | 3420 |
| Alina | Rodriguez | arodriguez@example.com | 6742 |
| Amit | Patel | amit.patel@example.com | 890 |
| Myali | Brown | myali.brown@example.com | 2150 |
If you want your message to include the subscriber's reward point balance, specify the
identifier of the data object (CustomerRewardMembers__mo) and the
identifier of the column to return (RewardsPoints__c). Next,
cross-reference the email addresses in the marketing object
(EmailAddress__c) with the target email addresses in your data graph
($dataGraph.Email__c). The AMPscript code resembles this example:
%%[
SET @points = Lookup(
CustomerRewardMembers__mo,
RewardsPoints__c,
EmailAddress__c,
$dataGraph.Email__c)
]%%
<p>Your reward points balance is %%=v(@points)=%%!</p>Alternatively, to render this content by using Handlebars, use this example:
{{set points=(
get
(queryFirst
type="MO"
object="CustomerRewardMembers__mo"
EmailAddress__c=$dataGraph.Email__c
)
"RewardsPoints__c"
)}}
<p>Your reward points balance is {{points}}!</p>With this code in place, Michael Chen’s email says “Your reward points balance is 3420!” and Myali Brown’s email says “Your reward points balance is 2150!”
Preview and Test Message Content
Before you publish an email that contains AMPscript or Handlebars code, preview and test it to make sure that your code produces the expected result. Verify that the correct data appears for several recipients and that your content renders properly. For more information, see Create an Email in Code View in Marketing Cloud Next.

