<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: IF statement to check if crm_object query returns no results in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/532171#M26302</link>
    <description>&lt;P&gt;Oh, figured it out. That suggestion made total sense, but seems like the crm_objects never returns a complete null result, even if there's no records that match the query. So it would always just render a white space in my email.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Had another look at the documentation, and &lt;A href="https://developers.hubspot.com/docs/cms/hubl/functions#crm-objects" target="_blank" rel="noopener"&gt;crm_objects returns a total parameter&lt;/A&gt;. So I just added:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if events.total == "0" %}
Some test text here

{% else %}
The for loop

{% endif %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then purposefully set my query to mess up to test results, and it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Nov 2021 13:24:26 GMT</pubDate>
    <dc:creator>Bob2245</dc:creator>
    <dc:date>2021-11-25T13:24:26Z</dc:date>
    <item>
      <title>IF statement to check if crm_object query returns no results</title>
      <link>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/531547#M26275</link>
      <description>&lt;P&gt;So, we've built a programmatic email template for a client that queries a custom object for records matching certain criteria, then returns a bunch of fields of those records to be displayed in the email.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These custom object records are fed to Hubspot on a daily basis from an external system. There's days when the external system has no new records to feed, so the email would be sent with a blank section. So I'd like to use an IF statement to display fallback content in case no records were found. Here's the snippet of code where this happens. Piece in the red block is what I added to make this work, but it didn't seem to work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bob2245_0-1637764026026.png" style="width: 999px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/54484i28943BA8E0FC1E06/image-size/large?v=v2&amp;amp;px=999" role="button" title="Bob2245_0-1637764026026.png" alt="Bob2245_0-1637764026026.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I understood something like this should be possible, but I'm guessing this isn't it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 14:27:35 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/531547#M26275</guid>
      <dc:creator>Bob2245</dc:creator>
      <dc:date>2021-11-24T14:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement to check if crm_object query returns no results</title>
      <link>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/531658#M26282</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/161485"&gt;@Bob2245&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can remove the &lt;STRONG&gt; == null&lt;/STRONG&gt; and put your for loop ablove the else.&amp;nbsp; Then below the else, add your alternative message.&lt;/P&gt;
&lt;P&gt;EG:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if events %}
  this will occur if there is a value for events
{% else %}
  this will occur if there is NOT a value for events
{% endif %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 16:34:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/531658#M26282</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-11-24T16:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement to check if crm_object query returns no results</title>
      <link>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/532171#M26302</link>
      <description>&lt;P&gt;Oh, figured it out. That suggestion made total sense, but seems like the crm_objects never returns a complete null result, even if there's no records that match the query. So it would always just render a white space in my email.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Had another look at the documentation, and &lt;A href="https://developers.hubspot.com/docs/cms/hubl/functions#crm-objects" target="_blank" rel="noopener"&gt;crm_objects returns a total parameter&lt;/A&gt;. So I just added:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if events.total == "0" %}
Some test text here

{% else %}
The for loop

{% endif %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then purposefully set my query to mess up to test results, and it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 13:24:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/IF-statement-to-check-if-crm-object-query-returns-no-results/m-p/532171#M26302</guid>
      <dc:creator>Bob2245</dc:creator>
      <dc:date>2021-11-25T13:24:26Z</dc:date>
    </item>
  </channel>
</rss>

