Check if contact property is empty in email templates
SOLVE
Hello, I am trying to figure out how to check if a contact property is empty via hubl we have so far
{% if contact.added_to_our_list_after is not defined or contact.added_to_our_list_after == '' or contact.added_to_our_list_after is none %}
<!-- Do something if the property is empty, not defined, or null -->
<p>The contact has not been added to our list after a specific date.</p>
{% else %}
<!-- Do something if the property is not empty -->
<p>The contact was added to our list after: {{ contact.added_to_our_list_after }}</p>
{% endif %}
But it doesn't work, it always goes into the else statement, so something I am clearly missing with the value of contact.added_to_our_list_after when blank
There is the "type" function that will function similarly to typeof in JS.
In your case its important to remember that date fields are nullable meaning these type of values are designed to hold a null value representing the absence of a value. Thus an "empty" date property will be null to represent the no date.
Check if contact property is empty in email templates
SOLVE
Hey, @MNick2👋 I have a few additional troubleshooting questions for you:
— Have you tried adding a temporary debugging line in your template to output the value of contact.added_to_our_list_after to see what is actually being returned? This may help you understand why the logic might be falling into the else statement.
— Ensure that contact.added_to_our_list_after is being returned as a string. Sometimes date fields might behave differently, especially if they are being treated as Date objects. If so,
comparing it against a default date might help:
{% if contact.added_to_our_list_after == '1970-01-01T00:00:00Z' or contact.added_to_our_list_after == '' or contact.added_to_our_list_after is none %}
If you've already ruled these out, or they don't help, please let me know, and we can tag in a few of our community members who are experts with HubL.
Talk soon! — Jaycee
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !
There is the "type" function that will function similarly to typeof in JS.
In your case its important to remember that date fields are nullable meaning these type of values are designed to hold a null value representing the absence of a value. Thus an "empty" date property will be null to represent the no date.
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !