<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Querying nulls logic</title><link>https://community.appian.com/discussions/f/general/28091/querying-nulls-logic</link><description>I was making a query today in which I wanted to find entries based on a particular field and if that field happens to be null, I want all the entries that have that field null. I ended up with 2 filters, one that looks for entries when the value is not</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109662?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2023 20:27:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:859db6a1-9e5f-49a6-8586-380487dbfbdc</guid><dc:creator>Marco</dc:creator><description>&lt;p&gt;Yes, that is pretty much what I did.. And it works fine. I just wish I could have just put true on that ignore parameter and have the one filter actually search for nulls, instead of the 2 filter workaround. But it is what it is. Thank you very much for the response!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109661?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2023 20:05:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5a983053-b151-46e8-9614-b07f201fe279</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Those of us who&amp;#39;ve been around for a few years now will remember that in the older days, the &lt;em&gt;&lt;strong&gt;only option&lt;/strong&gt;&lt;/em&gt;&lt;strong&gt;&lt;/strong&gt; was wrapping optional query conditions in if() statements - there was no applyWhen and there was no &amp;quot;ignore empty&amp;quot; switch.&amp;nbsp; It worked, but it added a lot of extra cumbersomeness and made for some awkward situations (and led more junior devs into error-traps sometimes).&lt;/p&gt;
&lt;p&gt;I believe both options were implemented and made available fairly close to each other time-wise (to the best of my fuzzy recollection), and though they&amp;#39;re slightly logically redundant with each other, they both solve different use cases and add necessary flexibility.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109660?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2023 19:42:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:690388db-ab10-4f44-a22c-bfb84b570aa1</guid><dc:creator>Nicole Walter</dc:creator><description>&lt;p&gt;So I&amp;#39;m assuming you mean something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!mySearchString: ri!input_string,
  a!queryEntity(
    entity: cons!My_Data_Entity,
    query: a!query(
      logicalExpression: a!queryLogicalExpression(
        filters: {
          if(
            a!isNullOrEmpty(value: local!mySearchString),
            a!queryFilter(
              field: &amp;quot;myField&amp;quot;,
              operator: &amp;quot;is null&amp;quot;,
              value: &amp;quot;&amp;quot;
            ),
            a!queryFilter(
              field: &amp;quot;myField&amp;quot;,
              operator: &amp;quot;=&amp;quot;,
              value: local!mySearchString
            )
          )
        },
        ignoreFiltersWithEmptyValues: false
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Personally, I&amp;#39;d argue it looks cleaner to just use the applyWhen/ignoreFiltersWhenEmpty arguments than it is adding an if statement to the query, but functionally they should be equivalent. You could probably get away with doing either, honestly.&lt;br /&gt;&lt;br /&gt;It might be weird if you have additional filters on top of this, because you&amp;#39;d have a list of filters as the value for the filters argument in your logical expression, but then one of the values would actually be your if statement. In that case I think it would definitely be cleaner to do it my way instead of using an if statement. That being said, in the code above (where we only have this filter), I think its fair to say it can go either way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109658?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2023 19:29:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1ffc5666-cf8a-4f7c-b63a-edc924b5aa7b</guid><dc:creator>Marco</dc:creator><description>&lt;p&gt;I see, thanks for your response. I do have a question though. Why is this more beneficial than wrapping the two filters in an if statement? Seems about the same functionally as far as I can tell, and it isn&amp;#39;t particularly shorter/easier to write out. So what makes this the better option between the two?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109590?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2023 20:17:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2ed2c888-b0f2-4dbf-8743-c068c0978466</guid><dc:creator>Nicole Walter</dc:creator><description>&lt;p&gt;Hi Marco! I&amp;#39;ve definitely run into this problem before, and as others in this thread have acknowledged, the&amp;nbsp;&lt;span&gt;ignoreFiltersWithEmptyValues parameter in your given logical expression does not work well with your use case. However, with a slight adjustment we can actually get value out of it while still allowing for your null filter! &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Basically, you still keep your original query on your given search input, but you add another filter that only applies when your input is null. This covers your null case and your non-null case.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It would look something like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!mySearchString: ri!input_string,
  a!queryEntity(
    entity: cons!My_Data_Entity,
    query: a!query(
      logicalExpression: a!queryLogicalExpression(
        filters: {
          a!queryFilter(
            field: &amp;quot;myField&amp;quot;,
            operator: &amp;quot;is null&amp;quot;,
            value: &amp;quot;&amp;quot;,
            applyWhen: a!isNullOrEmpty(value: local!mySearchString)
          ),
          a!queryFilter(
            field: &amp;quot;myField&amp;quot;,
            operator: &amp;quot;=&amp;quot;,
            value: local!mySearchString
          )
        },
        ignoreFiltersWithEmptyValues: true
      )
    )
  )
)&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To your original point, the only reason this solution works is&amp;nbsp;&lt;em&gt;because&amp;nbsp;&lt;/em&gt;of the ignoreFilters value, not despite it. The purpose of that condition is to avoid making us have to wrap each of our filters in an if statement (or something equivalent), which actually makes it quite useful!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you have any questions about this please let me know, I&amp;#39;m more than happy to provide more explanation&amp;nbsp;&lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109517?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 20:05:35 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:12f262fd-63b6-4eee-b73f-1f4eb7d43d68</guid><dc:creator>Abhay Dalsaniya</dc:creator><description>&lt;p&gt;I believe&amp;nbsp;&lt;span&gt;ignoreFiltersWithEmptyValues&amp;nbsp;is very useful if it is used&amp;nbsp;correctly.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Querying nulls logic</title><link>https://community.appian.com/thread/109486?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 16:18:36 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:aae64b47-7640-4b84-8f8e-7c8c68007f4c</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;The purpose of this parameter is to support optional filters without the hassle of adding additional code. Your use case does not fit into this assumption, so you might have to change the settings.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>