Adding Custom Object Field as Token via Email Script | Community
Skip to main content
Sheila_McGrath
New Participant
November 25, 2019
Solved

Adding Custom Object Field as Token via Email Script

  • November 25, 2019
  • 1 reply
  • 3172 views

I have an email where i'm trying to add in tokens for the Make and Model of a new car that was just purchased. The Custom Object is "Account" and the field names are "Make" and "Model" which are housed in that account. Because a lead can have multiple accounts, the Make and Model are sometimes in the first record in the Custom Object and sometimes in the second. I'm trying to write the email script to look for the field "Product Code" = 388 which points out which account needs to serve up the Make and Model. I've read through numerous amounts of documentation and cannot seem to find how to adjust the scripts in the documentation for my scenario. Any help would be appreciated. My current script for a "Make" token, is as follows:

#foreach($account in $account_cList)
#if ($account.productcode == "388") {
>$foreach ${account.make}
}
#end

What am I doing wrong?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

the Make and Model are sometimes in the first record in the Custom Object and sometimes in the second. 

Let's not say "first" and :"second". Following the Zero-One-Infinity (ZOI) rule, if there's a second, there can also be a third and a fourth and a 99th. So better to say "the match can be in any of the CO records."

#foreach( $account in $account_cList )
#if( $account.productcode.equals("388") )
#set( $matchedAccount = $account )
#break
#end
#end
#if( $matchedAccount )
Found account with Make ${matchedAccount.make} and Model ${matchedAccount.Model}
#else
No matching account found.
#end‍‍‍‍‍‍‍‍‍‍‍

Of course I'm assuming the property names are productcode, make, and model (case-sensitive) but only you would know for sure, by checking off those properties in the tree in Script Editor to figure out their Velocity aliases.

Also, don't use ==, use equals(), as the former can cause hard-to-find bugs.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 25, 2019

the Make and Model are sometimes in the first record in the Custom Object and sometimes in the second. 

Let's not say "first" and :"second". Following the Zero-One-Infinity (ZOI) rule, if there's a second, there can also be a third and a fourth and a 99th. So better to say "the match can be in any of the CO records."

#foreach( $account in $account_cList )
#if( $account.productcode.equals("388") )
#set( $matchedAccount = $account )
#break
#end
#end
#if( $matchedAccount )
Found account with Make ${matchedAccount.make} and Model ${matchedAccount.Model}
#else
No matching account found.
#end‍‍‍‍‍‍‍‍‍‍‍

Of course I'm assuming the property names are productcode, make, and model (case-sensitive) but only you would know for sure, by checking off those properties in the tree in Script Editor to figure out their Velocity aliases.

Also, don't use ==, use equals(), as the former can cause hard-to-find bugs.

Sheila_McGrath
New Participant
November 25, 2019

Thank you, @Sanford Whiteman‌! This did the trick. Appreciate the help and all your documentation!

SanfordWhiteman
New Participant
November 25, 2019

Sure, can you mark my answer with the code as Correct?