So the first problem is if Clinic ID has no value, it's printing the variable in the email.
The second issue is if the value of clinicID doesn't exist, it's still printing the variable in my email (like the below)
$clinics.Map[$CID]["NME"]
So that is why I am saying the IF statements are not evaluating properly. I am testing with 3 emails, one covering each use case. Proper ID, Missing ID, and Wrong ID
The output is exactly what you'd expect from the code you have. It's evaluating properly.
$reference.isEmpty() is null if $reference is null, because you can't check emptiness of non-String/Array values.
!$reference.isEmpty() is true if $reference is null, because the null is coerced to a Boolean when you use !.
Ok that makes sense, so how do I check if it's null? Putting null I get an error.
if $reference is null
$display.alt($reference,"").isEmpty() is true
if $reference is ""
!$display.alt($reference,"").isEmpty() is false
if $reference is "Sandy"
!$display.alt($reference,"").isEmpty() is true
I'm sorry, I am really not getting how to check if the value is null, that's the part I have been stuck on for this entire post.
Doing this
if $reference is null
$display.alt($reference,"").isEmpty() is true
Is always returning true for me, regardless of the value of "Reference",
#set( $NME = "Physiotherapy" )
#set( $CID = $lead.ClinicID )
#if( ${CID.isEmpty()} == 'false' && ${clinics.Map.containsKey($CID)} == 'true' && ${clinics.Map[$CID].containsKey("NME")} == 'true' )
#set( $NME = $clinics.Map[$CID]["NME"] )
<br>
All statements validate to TRUE STRING<br>
#end
$CID
#if ( $display.alt($CID,"").isEmpty() )
The clinic has a value
#end
$display.alt() returns its 1st argument if the 1st argument is anything other than null. Otherwise, it returns the 2nd argument.
The method is designed to be a null coalescing function, like COALESCE in SQL.
It's not possible for $display.alt($reference,"").isEmpty() to return true if $reference is a non-empty String.
So this still isn't working, it must mean that when that data doesn't exist it's something other then "null", how can we figure out what is going on?
It always returns true for me, it doesn't matter if there is a clinic ID or not, and the contains never prints even if it does exist.
If $lead.ClinicID ) does not have a value in marketo, I want to print an alternative instead, I have tried to check if it's null, true/ false, or an empty string, but none of them are working properly.
How do I check if CID has a value or not?
#set( $CID = ${lead.ClinicID} )
#if( $lead.clinicId.isEmpty() )
clinicId is explicitly empty
#elseif( $display.alt($lead.clinicId,"").isEmpty() )
clinicId is null
#else
clinicId has a non-empty String value ${lead.clinicId}
#end
No change:
$lead.clinicId has a value of 123456 (Based on data in field and what i print on the page)
The exact Code I did, CID is printing either the numbers (123456) or nothing as expected.
#set( $CID = $convert.toString( ${lead.ClinicID} ) )
#if( ${CID.isEmpty()} == 'false' && ${clinics.Map.containsKey($CID)} == 'true' && ${clinics.Map[$CID].containsKey("NME")} == 'true' )
#set( $NME = $clinics.Map[$CID]["NME"] )
<br>
All statements validate to TRUE STRING<br>
#end
$CID
Below is the content<br/>
#if( $lead.ClinicID.isEmpty() )
clinicId is explicitly empty
#elseif( $display.alt($lead.ClinicID,"").isEmpty() )
clinicId is null
#else
clinicId has a non-empty String value ${lead.ClinicID}
#end