For parsing variables for the respective values on the email content html blocks, I usually have 2 kinds of variables.

The first case. The variable is defined on the sendable Data Extension. The second case. I create and set a new variable using Ampscript and lookup a value from a DE.

I use the notation %%=v(var)=%% for the first scenario or %%=v(@var)=%% for the second one.

My question is, what happens if the variable is neither defined on the sendable DE nor in the script. Still can I use it as %%=v(newVar)=%% where newVar is coming on the JSON from the request's payload?


While %%=v(varName)=%% works, the v() function isn't necessary. All that's required is %%varName%% outside of an AMPscript block or varName inside a block.

If the value you're referencing doesn't exist, the email won't compile or preview and your send will get aborted.

My rule of thumb -- no naked personalization strings. I never use %%varname%% notation outside of AMPscript blocks, nor do I use varname in a block without a function around it.

Always set a variable for send context attributes or DE columns. Set their values with AttributeValue() so you can detect empty values and ensure they exist:


var @deColumn1
set @deColumn1 = AttributeValue("deColumn1")

if empty(@deColumn) then

  set @deColumn1 = "default value"



For parsing values from a payload, you can't just reference values by name -- you'll need to parse them out.

For example if you had this XML payload in a field value:

<?xml version="1.0" encoding="UTF-8"?>

...you'd parse can parse it like this:


var @xml, @isXML, @nodes, @rowCount
set @xml = AttributeValue("xml")

if indexOf(@xml,"<cart>") > 0 then

  set @nodes = BuildRowsetFromXML(@xml,"/cart/items/item",0)
  set @rowCount = rowcount(@nodes)

  if @rowCount > 0 then

    for @i = 1 to @rowCount do

      var @nodepath
      var @sku
      var @name
      var @url

      set @nodepath = concat("/cart/items/item[",@i,"]/")

      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"sku"))) > 0 then
          set @sku = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"sku"),0),1),'Value')

      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"name"))) > 0 then
          set @name = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"name"),0),1),'Value')

      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"url"))) > 0 then
          set @url = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"url"),0),1),'Value')

      if not empty(@sku) and not empty(@name) and not empty(@url) then


       <br><a href="%%=redirectto(@url)=%%">%%=v(@sku)=%%</a> - <a href="%%=redirectto(@url)=%%">%%=v(@name)=%%</a>



    next @i


   outputline(concat("<br>no products found"))



  outputline(concat("<br>no XML found"))



Or if you had this JSON payload in a field value:


...you'd parse it like this

<script runat="server">

var json = Attribute.GetValue('json');
var jsonObj = Platform.Function.ParseJSON(json);

if (jsonObj.length > 0) {

  for (var i = 0; i < jsonObj.length; i++ ) {

      var item = jsonObj[i];

      <br><a href="%%=redirectto(@url)=%%">%%=v(@sku)=%%</a> - <a href="%%=redirectto(@url)=%%">%%=v(@name)=%%</a>
      <script runat="server">


} else {

  Write("no products found")


  • I have referred to this endpoint ://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/messageDefinitionSends.htm and specifically to the SubscriberAttributes variable. So in case I want to only send a variable but that doesn't exists in the AmpScript code, only in the html email template, is not possible to get the value and reference it, correct? Let's assume that the script control all the variable parsing, constructing a long string as the email. So, if nor in the DE is defined, then there's no way to use such variable from the SubscriberAttributes object, correct?Tks – mario ruiz May 6 '19 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.