SOLVED

Re: Velocity Set a Default for Error/Null/If Statement Fails

Go to solution
nhabischWings
Level 5

Velocity Set a Default for Error/Null/If Statement Fails

Hello, this might be a very simple question, but running the following personalization script:

 

##Standard Velocity Date/Time Fields
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Chicago") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
##Set blank array for future values
#set( $firstNames = [] )
##iterate Customer Profile records and set Membership Opening Date to usable value for script
#foreach ( $item in $customerProfilesList )
#set( $membershipOpeningDate = $convert.parseDate(
    $item.membershipDate,
    $ISO8601DateOnly, 
    $defaultLocale, 
    $defaultTimeZone 
) )
##Sets difference from Membership Opening Date between -4 and 0 days
#set( $pastDiff = -4 )
#set( $currentDiff = 0 )
#set( $diffDays = $date.difference($calNow,$membershipOpeningDate).getDays().intValue() )
#set( $acceptableDiffs = [$pastDiff..$currentDiff] )
##Checks if qualifying Lead is a Member and a Person
#if ( ( $acceptableDiffs.contains($diffDays) ) && ($item.membershipStatus.equals("Member")) && ($item.customerType.equals("PERSON")) && ($item.age >= 18) && (!$item.membershipDate.isEmpty()) && ($item.NMOBanditGroup.equals("1.00000000")) )
#set ( $void = $firstNames.add($item.firstName) )
#else
#end
#end
##Display full names that meet conditional in clean formatting
${display.list($firstNames)}

 

It runs correctly, but what I'm looking to do is set essentially a "default" personalization like "Customer" if for some reason the Smart List plus script doesn't find a value or errors or whatever reason it would be blank instead of pulling in a value.

I know that inherently that would falls under #else, but since I am pulling values into the blank $firstNames array and using $displaylist outside of the #foreach loop - is there a way to check if the $firstNames array is blank after the initial #if statement and then set the array to display "Customer"?
I tried the following:

##Standard Velocity Date/Time Fields
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/Chicago") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
##Set blank array for future values
#set( $firstNames = [] )
##iterate Customer Profile records and set Membership Opening Date to usable value for script
#foreach ( $item in $customerProfilesList )
#set( $membershipOpeningDate = $convert.parseDate(
    $item.membershipDate,
    $ISO8601DateOnly, 
    $defaultLocale, 
    $defaultTimeZone 
) )
##Sets difference from Membership Opening Date between -4 and 0 days
#set( $pastDiff = -4 )
#set( $currentDiff = 0 )
#set( $diffDays = $date.difference($calNow,$membershipOpeningDate).getDays().intValue() )
#set( $acceptableDiffs = [$pastDiff..$currentDiff] )
##Checks if qualifying Lead is a Member and a Person
#if ( ( $acceptableDiffs.contains($diffDays) ) && ($item.membershipStatus.equals("Member")) && ($item.customerType.equals("PERSON")) && ($item.age >= 18) && (!$item.membershipDate.isEmpty()) && ($item.NMOBanditGroup.equals("1.00000000")) )
#set ( $void = $firstNames.add($item.firstName) )
#elseif ($firstNames.isEmpty())
#set ( $void = $firstNames.add("Wings Member") )
#else
#end
#end
##Display full names that meet conditional in clean formatting
${display.list($firstNames)}

I'd think that would take the blank array and output "Wings Member" into the list - which would then show up during an email preview as it would set a default value, but maybe not?

Am I on the right track?


Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
nhabischWings
Level 5

Re: Velocity Set a Default for Error/Null/If Statement Fails

Nevermind, solved my own issue 🙂
Needed to add "#set ( $void = $firstNames.add("Wings Member") )" after the #else parameter.
Duh! 🙂

View solution in original post

1 REPLY 1
nhabischWings
Level 5

Re: Velocity Set a Default for Error/Null/If Statement Fails

Nevermind, solved my own issue 🙂
Needed to add "#set ( $void = $firstNames.add("Wings Member") )" after the #else parameter.
Duh! 🙂