SOLVED

Re: Velocity script token conditional "not" is not working

Go to solution
Kevin_Stinson
Level 3

Velocity script token conditional "not" is not working

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script token conditional "not" is not working

In that case:

 

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

 

 

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script token conditional "not" is not working


#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

Re: Velocity script token conditional "not" is not working

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
Level 10 - Community Moderator

Re: Velocity script token conditional "not" is not working

In that case:

 

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

 

 

Kevin_Stinson
Level 3

Re: Velocity script token conditional "not" is not working

@SanfordWhiteman 

Thanks so much for your help.

I had still some issue with the code where I checked for Salutation not being blank at the top of the code and then testing it again in the male/female sections but I removed that check as your code made that not necessary and it is working in all scenarios now.

Question: are the double number signs at the end of the code where the set is used to ensure there is no white space?

Here is the final code:

##check if salutation is NOT populated with Herr or Frau, set greeting
#if( !$display.alt(["Herr","Frau",""]).contains($lead.Salutation) )
	#set($greeting = "${lead.Salutation},")##
##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
Level 10 - Community Moderator

Re: Velocity script token conditional "not" is not working


Question: are the double number signs at the end of the code where the set is used to ensure there is no white space?


Exactly. But you don't put it after a #set() — only in output.

 

I still would touch up that code a bit. Shouldn't use formal notation (curly braces) in conditions. And == is buggy, use equals().

##check if salutation is NOT populated with Herr or Frau, set greeting
#if( !$display.alt(["Herr","Frau",""]).contains($lead.Salutation) )
#set($greeting = "${lead.Salutation},")
##check if the lead.Gender is male
#elseif( $lead.Gender_.equals("Male") || $lead.Gender_.equals("Herr") || $lead.Salutation.equals("Herr") )
#set($greeting = "Sehr geehrter Herr ${lead.LastName},")
##check is the lead.Gender is female
#elseif( $lead.Gender_.equals("Female") || $lead.Gender_.equals("female") || $lead.Gender_.equals("weiblich") || $lead.Salutation.equals("Frau") )
#set($greeting = "Sehr geehrte Frau ${lead.LastName},")
##otherwise, use default
#else
#set($greeting = "Sehr geehrte Damen und Herren,")
#end
##print the greeting
${greeting}##

 

This would also be easier to read if you used .contains() on a collection wherever possible, as I did with the first condition.

Kevin_Stinson
Level 3

Re: Velocity script token conditional "not" is not working

Thanks again. I made that change.