Variable fields can be merged into
an email message utilizing the scripting
language, AMPscript.
In Content Builder:
- Link your email message to your source data extension that will hold the data you're trying to merge into the email. First, click the person icon. Second, click 'Choose New Data Source', to select your data extension.
- Toggle to HTML Editor in the content
builder to insert your variable.
- From the drop-down, select the variable you'd like to merge into the content or type the field name out using %% before and after the variable name, like %%fname%%.
- Click "Next" or "Preview and Test" and
select your
testing data extension to see if your
variable merged without errors.
*NOTE: If using the content editor in content
builder, note that formatting can result in
errors. So, be sure to toggle to the HTML
editor to check for and remove any missplaced
formatting.
Advanced Lookup Tables:
If your data is greater than the number
of fields available in your source or
target data extensions, you may create a
lookup table or matrix.
- Create your data extension with the
1st field as the lookup value that
will match the two tables, for
example, player_id or tier.
- Add all other table headers/field
names to your lookup or matrix data
extension. (🏆Best Practice: Do not
include spaces in the field
names).
- Import the data into the lookup table
or matrix.
- In the email message, paste the
following AMPscript at the top of your
HTML or create an HTML content block
at the top of your email message and
paste the following AMPscript.
%%[set @rows = LookupRows("MatrixName","FirstColumnInMatrix",TargetDataExtensionFieldName) if RowCount(@rows) > 0 then set @row = Row(@rows,1) set @MatrixFieldtoLookup = Field(@row,"MatrixFieldtoLookup") endif]%%
- In the AMPscript, edit "MatrixName", and replace it with the name of your
Lookup table/Matrix data
extension.
- In the AMPscript, edit
"FirstColumnInMatrix" value, and replace
it with the name of the lookup field
you created in Step 1.
- Edit TargetDataExtensionFieldName to
match the value that is in your target
data extension that will match the
two tables (see step 1).
- Change @MatrixFieldtoLookUp to the
value you'd like to use as the
Variable in your email, for example,
@firstname.
- In the Parenthesis, change
"MatrixFieldtoLookup" to the name of
the field in the matrix that will
return the variable value in step 9.
For example, if the field you created
in your matrix is "Fname". You'll need to edit the value in the parenthesis to
fname.
- Copy " set @MatrixFieldtoLookup = Field(@row,"MatrixFieldtoLookup")" and paste for each variable you want to merge into your email. Your final AMPScript could look like this:
%%[set @rows = LookupRows("AugustMatrix","Tier",tier) if RowCount(@rows) > 0 then set @row = Row(@rows,1) set @firstname = Field(@row,"fname") set @lastname = field(@row,"lname") set @total = field(@row,"total") endif]%%
In this example, you have created 3 variables that can be used to merge into the email. - In the body of the email, you will call the AMPscript variable by replacing the field/variable name.
%%=v(@Variable)=%%
*
*NOTE: If there are spaces in
the field name, you must apply brackets
around the variable name.
For
example, First Name becomes [First
Name]. So, the AMPscript would
be %%=v([@First Name])=%%. If
that doesn't work, rename your
variable in the AMPscript in both
the
lookup and the variable body copy
to
remove the
space.
Additional Resources:
AMPscript Formatting is also
available in Content Builder to format various
elements of your copy.
%%=Uppercase(fieldname)=%%
%%=lowercase(fieldname)=%%
%%=Propercase(fieldname)=%%
As well as date, time, number, and
currency formatting:
More helpful info: AMPscript
101