I'm trying to write a Velocity Script statement that looks at our account numbers to see if it's blank. If the account number is blank, I want it to write the Company Name instead. If the Account Number is not blank, I want it to write the Account Number. This is my first time using Velocity Script, so I'm probably doing it wrong.
Here's what I have based on scouring Community. When I send the test email as someone with an Account Number, I get "${my.vSCRIPT_2}" where my Account Number should be.
#if(${lead.Oracle_Account_Number__c} == "")
${lead.Company}
#else
${lead.Oracle_Account_Number__c}
#end
I'm happy to do if differently if there's a better way!
Solved! Go to Solution.
Are you sending a sample, or a real email (should use the latter)?
Don't bother with formal notation (curly braces) in a directive like #if. Just makes the code harder to read. (Also as far as this forum goes, you should syntax highlight your code as Java to set it aside, as I do below.)
Aside from the style question, what you're doing will work, but I prefer isEmpty().
#if( $lead.Oracle_Account_Number__c.isEmpty() )
I recommend my Marketo/Velocity articles if you're getting into this: http://blog.teknkl.com/tag/velocity
Oh -- and make sure all fields referenced in your VTL are checked in the right-hand tree.
Hi Sanford,
Thanks for the quick reply. I changed to isEmpty(), but ${my.vSCRIPT_2} is still showing in my email instead of my Account Number or Company Name.
Is there something else I could be doing wrong? I'm using the Email Script Token and the fields referenced are checked in the tree.
I was sending a sample email with a lead's information so that I could test it to ensure it works. I didn't realize I have to send a real email to myself to test it. Good to know!
Thanks for the help!