SOLVED

Re: Need help with Velocity Scripting for #if and #else statements

Go to solution
Lisandrafer1
Level 1

Need help with Velocity Scripting for #if and #else statements

Hi I need some help on a velocity script token I am trying to create to use in a text based email. Here's what I'm trying to do:

My email is a notification that goes out after a customer fills out a form and the reason I'm going this route is because we're over the 40 token limit that you can include in an email. However not every form fill will have over 40 fields to display as some of those fields are conditional on the form. We have fields for up to 4 users. In the email I want the data that the user 2 has inputted in the form to display only if that field is not empty (if statement only needs to be on the User name since if this is empty the rest of the fields would be too). Some of the fields that they are filling out are Boolean fields (so they check them or leave them blank) and rather than my email having 1's and 0's I want the script to say Yes or No on that particular field and display what the name of the field is. Here's example data input:

User 2 Name: Jane Doe

User 2 Email: Jane.Doe@domain.com

User 2 Title: Specialist

User 2 Phone: 000-000-0000

User 2 Billing Accounts: ACT-12345

Boolean Fields:

User 2 Billing Invoices: 0

User 2 Order Status: 1

User 2 Support Tickets: 0

User 2 Service Status: 1

 

Below is the email script token I wrote based on what I've been able to gather on how to put something like this together but I am either missing something or the syntax is incorrect somewhere because I keep getting a validation error when I try to approve the email with this script token. Any ideas on what I'm doing wrong?

 

$if ( $lead.user2Name.isEmpty() )
#set ("No Additional Users Requested")
#else
#set ("User Name: $lead.user2Name")
#set ("User Email: $lead.user2Email")
#set ("User Title: $lead.user2Title")
#set ("User Phone: $lead.user2Phone")
#set ("User Billing Accounts: $lead.user2BillingAccounts")
#end
$if ( $lead.user2BillingInvoices==("1") )
#set ("User Billing Invoices:Yes")
#else
#set ("User Billing Invoices:No")
#end
$if ( $lead.user2OrderStatus==("1") )
#set ("User Order Status: Yes")
#else
#set ("User Order Status: No")
#end
$if ( $lead.user2SupportTickets==("1") )
#set ("User Support Tickets: Yes")
#else
#set ("User Support Tickets: No")
#end
$if ( $lead.user2ServiceStatus==("1") )
#set ("User Service Status: Yes")
#else
#set ("User Service Status: No")
#end
1 ACCEPTED SOLUTION

Accepted Solutions
lukea
Level 3

Re: Need help with Velocity Scripting for #if and #else statements

Maybe you gave the answer yourself if you compare this posting's title with its content (#if versus $if)?

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Need help with Velocity Scripting for #if and #else statements

Can you please update your post to use the syntax highlighter (as Java) on your code snippets so they’re readable? Thanks.

SanfordWhiteman_1-1665549504137.png

 

lukea
Level 3

Re: Need help with Velocity Scripting for #if and #else statements

Maybe you gave the answer yourself if you compare this posting's title with its content (#if versus $if)?

Lisandrafer1
Level 1

Re: Need help with Velocity Scripting for #if and #else statements

Lesson learned, never write code at night. Totally missed that I wrote my if statements incorrectly. Thank you! This has solved the issue I was having and now I can finally save the email and test my script!! 🙂

SanfordWhiteman
Level 10 - Community Moderator

Re: Need help with Velocity Scripting for #if and #else statements

There are still errors in your code.

 

(1) You should be using equals(), not the == operator (the latter has unexpected consequences):

#if( $lead.user2BillingInvoices.equals("1") )

 

(2) This is a syntax error:

#set ("User Billing Invoices:Yes")

 

You presumably want something like:

#set( $UserBillingInvoices = "Yes" )