SOLVED

Re: Velocity Script if/else Statement

Go to solution
Dayna_Wellman3
Level 3 - Champion Alumni

Velocity Script if/else Statement

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!

Dayna Wellman
Campaign Operations Consultant @ Etumos
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script if/else Statement

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

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script if/else Statement

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script if/else Statement

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

Dayna_Wellman3
Level 3 - Champion Alumni

Re: Velocity Script if/else Statement

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.

Dayna Wellman
Campaign Operations Consultant @ Etumos
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script if/else Statement

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

Dayna_Wellman3
Level 3 - Champion Alumni

Re: Velocity Script if/else Statement

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!

Dayna Wellman
Campaign Operations Consultant @ Etumos