Using a my token to drive Velocity script

Anonymous
Not applicable

Using a my token to drive Velocity script

Hello,

I am trying to send an e-mail using the requestCampaign API call that will dynamically populate content in the e-mail body based on data passed into the campaign via my tokens.

I have a scenario where the API could be passed anywhere from 1 to 3 distinct token values that drive additional content in the e-mail.  The API would also be passed an integer indicating the number of distinct token values being used.  The token setup I have is this:

{{my.content1}}
{{my.content2}}
{{my.content3}}
{{my.contentCount}}

The e-mail needs to display differently depending on how much content is passed (e.g. data in only {{my.content1}} vs. data in all three tokens.

In this scenario, depending on which tokens have data, the {{my.contentCount}} token will be equal to 1, 2, or 3.

Currently my API call for an e-mail with 2 items of content looks like this:

{
   "input":
      {
         "leads" : [
            {
               "id" : 1234
            }
         ],
         "tokens" : [
            {
               "name": "{{content1}}",
              "value": "Content Item 1"
            },
            {
               "name": "{{content2}}",
              "value": "Content Item 2"
            },
            {
               "name": "{{contentCount}}",
              "value": "2"
            }
         ]
      }
}

My question is, can I use the {{my.contentCount}} token in my Velocity script as follows:

#set ( $count = ${my.contentCount} )

#if ( $count == 1 )

<tr>... {{my.content1}}... <tr/>

#elseif ( $count == 2 )

<tr>... {{my.content1}}... <tr/>
<tr>... {{my.content2}}... <tr/>

#elseif ( $count == 3 )


<tr>... {{my.content1}}... <tr/>
<tr>... {{my.content2}}... <tr/>
<tr>... {{my.content3}}... <tr/>

#end


Alternatively, how might one approach this scenario if not with Apache Velocity scripting?

Thanks to any and all who can help me work through this issue.

-MICHAEL
Tags (1)
1 REPLY 1
Anonymous
Not applicable

Re: Using a my token to drive Velocity script

I don't think you can use My Tokens in Velocity (Might be worth a quick test to see). However, you could populate fileds on a custom object and then have the script check the values of those- as an option.