Velocity Script if/else Statement | Community
Skip to main content
Dayna_Wellman3
New Participant
November 21, 2016
Solved

Velocity Script if/else Statement

  • November 21, 2016
  • 1 reply
  • 5696 views

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!

Best answer by SanfordWhiteman

Are you sending a sample, or a real email (should use the latter)?

1 reply

SanfordWhiteman
New Participant
November 21, 2016

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: blog.teknkl.com/tag/velocity

SanfordWhiteman
New Participant
November 21, 2016

Oh -- and make sure all fields referenced in your VTL are checked in the right-hand tree.