Velocity script to empty content based on value | Community
Skip to main content
New Participant
August 3, 2020
Solved

Velocity script to empty content based on value

  • August 3, 2020
  • 1 reply
  • 6827 views

I want to include some personalized content in my email that says Member since: XXXX where XXXX=year (contained in a data field).  And I want to populate the year if the field value is 2007 or later.  For anything earlier than 2007, I want to hide Member since: XXXX altogether.  

 

I'm using a Velocity script token in the email, but I don't know much about writing scripts and I don't know what to do on the second line below to hide the content.  I just guessed null() but it's not working.  Any ideas?

#if ($lead.MemberSince < 2007) null() #else Member since: $lead.MemberSince #end

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman
#if ($lead.MemberSince >= 2007) Member since: $lead.MemberSince #end

 

Just don't output anything if the condition doesn't match.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
August 3, 2020
#if ($lead.MemberSince >= 2007) Member since: $lead.MemberSince #end

 

Just don't output anything if the condition doesn't match.

New Participant
August 4, 2020

Thank you!  This makes sense, but I tried it and it shows up blank no matter what the year value is.  My token within the email is {{my.membersince}}, and I sent test emails using leads with values like 2009 and 2015.  

New Participant
August 4, 2020

After some testing, I can get things to "work" if I change the script to == 2007.  Examples:

 

For someone whose field value is 2007, it shows up as Member since: 2007

For someone whose field value is 2004, it shows up blank.

For someone whose field value is 2015, it shows up blank. 

 

#if ($lead.MemberSince == 2007) Member since: $lead.MemberSince #end

 

Not sure why the >= operator symbol won't work!