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?
Solved! Go to Solution.
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.
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.
Thank you, Sanford Whiteman! This did the trick. Appreciate the help and all your documentation!
Sure, can you mark my answer with the code as Correct?