Detect empty field with velocity | Community
Skip to main content
Franky_Ruyssch2
Level 4
August 9, 2019
Question

Detect empty field with velocity

  • August 9, 2019
  • 2 replies
  • 10531 views

I need to know if a certain field in the database is empty or not to create an email link with velocity scripting

#if ( ${lead.mkt3497link3} != "" ) 

   #set ...

#end

Doesn't seem to work, although the field is empty it is selecting the if cause.

For debug reasons I have displayed the "content" of that empty field : the system displays "${lead.mkt3497link3}" as the value for the field. So the field is not evaluated, it seems...

What am I doing wrong and what is the correct way the check for empty fields.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

SanfordWhiteman
Level 10
August 9, 2019

It sounds like you didn't check the field off in the tree in Script Editor.

The way you're checking is OK for a string, though I recommend you switch to

#if ( $lead.mkt3497link3.isEmpty() ) 

to avoid surprises due to datatype mismatches. And also don't use ${formal} reference notation unless you're outputting something or are absolutely sure you need it, as it invites syntax errors.

Caleb_Tupper
Level 1
February 7, 2020

Hi Franky,

Not sure if you found a solution yet. We were running into a similar velocity scripting problem and found a way to detect a null value:


#if(!${lead.insuranceExpirationDate})
<p>True </p>
#else

<p>False</p>

#end

 

Hope this helps!

Caleb TupperDigital Marketer and Data EnthusiastMarketo Certified Expert