Velocity script token conditional "not" is not working | Community
Skip to main content
Kevin_Stinson
Level 3
August 19, 2020
Solved

Velocity script token conditional "not" is not working

  • August 19, 2020
  • 1 reply
  • 4168 views

Hello I have been trying to get an email token working using a NOT operator but the token shows Herr or Frau when the salutation fields does contain these strings and not displaying the default greeting.

I have written the code in a couple different ways with the same result.

#if ($lead.Salutation != "Herr") #set($greeting = "${lead.Salutation},") #elseif ($lead.Salutation != "Frau") #set($greeting = "${lead.Salutation},") #else #set($greeting = "Sehr geehrte Damen und Herren,") #end ${greeting}

 Second try:

#if( !(${lead.Salutation} == "Herr") || !(${lead.Salutation} == "Frau") ) #set($greeting = "${lead.Salutation},") #else #set($greeting = "Sehr geehrte Damen und Herren,") #end ${greeting}

Hope someone can point out where I am going wrong.

Note this is part of a larger salutation script but I isolated down to this part not working.

thanks,

Kevin.

 

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

In that case:

 

#if( !$display.alt(["Herr","Frau",""]).contains($lead.Salutation) ) ${lead.Salutation},## #else Sehr geehrte Damen und Herren,## #end

 

 

1 reply

SanfordWhiteman
Level 10
August 19, 2020

#if ($lead.Salutation != "Herr") #set($greeting = "${lead.Salutation},") #elseif ($lead.Salutation != "Frau") #set($greeting = "${lead.Salutation},") #else #set($greeting = "Sehr geehrte Damen und Herren,") #end ${greeting}

 Second try:


This code translates as

 

if the salutation is not "Herr"

set greeting to "Herr"

if the salutation is not "Frau"

set greeting to "Frau"

otherwise

set greeting to "Sehr geehrte Damen und Herren,"

 

If the salutation is is "Frau" it gets set to "Herr"? If the salutation is "Herr" it gets set to "Frau"? And it'll never get set to the fallback. Surely that's not what you want.

 

More like:

 

#if( $display.alt(["Herr","Frau"]).contains($lead.Salutation) ) ${lead.Salutation},## #else Sehr geehrte Damen und Herren,## #end
Kevin_Stinson
Level 3
August 19, 2020

Thanks for looking Sanford, but I guess I was not clear in want I am trying to do.

I am trying to filter out Herr or Frau so they are not displayed, I only want to show any salutations that are anything but those and not empty.

Here is the longer code that has all the pieces if that helps.

 

 

##check if salutation is populated #if( !$lead.Salutation.isEmpty() ) ##filter out salutations with Herr or Frau so they are not displayed #if( !(${lead.Salutation} == "Herr") || !(${lead.Salutation} == "Frau") ) #set($greeting = "${lead.Salutation},") #end ##check if the lead.Gender is male #elseif((${lead.Gender_} == "Male") || (${lead.Gender_} == "Herr") || (${lead.Salutation} == "Herr")) #set($greeting = "Sehr geehrter Herr ${lead.LastName},") ##check is the lead.Gender is female #elseif(${lead.Gender_} == "Female") || (${lead.Gender_} == "female") || (${lead.Gender_} == "weiblich") || (${lead.Salutation} == "Frau")) #set($greeting = "Sehr geehrte Frau ${lead.LastName},") ##otherwise, use default #else #set($greeting = "Sehr geehrte Damen und Herren,") #end ##print the greeting ${greeting}

 

 

 

 

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
August 20, 2020

In that case:

 

#if( !$display.alt(["Herr","Frau",""]).contains($lead.Salutation) ) ${lead.Salutation},## #else Sehr geehrte Damen und Herren,## #end