<?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>Array with no items but length still &amp;gt; 0</title><link>https://community.appian.com/discussions/f/rules/39895/array-with-no-items-but-length-still-0</link><description>Hello, again. 
 
 This is a strange one.... and I&amp;#39;m on version 24.1.281.0 
 I have two expression rules... one generates some error messages (or none) and the other deals with the errors. However, in the scenario where the first expression rule generates</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152267?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:33:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fbd5f856-43e0-4716-94aa-b30beb03e706</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;Yep.&amp;nbsp; Tested and it works.&amp;nbsp; Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152266?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:25:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ec701ffa-871e-4306-be00-437e8080e100</guid><dc:creator>Harsha Sharma</dc:creator><description>&lt;p&gt;Given the usecase length() function is not suitable here. It seems length() in expression 2 is considered as a string rather than an array which is why 1 is returned. Below code might explain the deviation between 0 sometimes and sometimes 1. The difference is just whether its an array or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!map(
  arrayLength: length({ &amp;quot;&amp;quot; }), /*returns 0*/
  stringLength: length(&amp;quot;&amp;quot;) /*returns 1*/
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;So,&amp;nbsp;In practice, as mentioned by almost everyone here, a!isNullOrEmpty() is best solution for cases like this.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152265?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:25:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2906c056-68c2-44b8-98cf-fa7d2bfcd791</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;So, overall, the answer is to use isNullOrEmpty to test a list for no items.&amp;nbsp; I had never considered this thinking it was more a string function than an array functions.&lt;/p&gt;
&lt;p&gt;Still, there is a technical nuance here I would like to understand if I can (and if I even have time to).&amp;nbsp; It may have something to do with what osanchea is saying about using Map vs Dictionary.&amp;nbsp; I might try to play with that and see if it helps.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you, all for your responses!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152264?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:23:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:63f49345-1b18-44e3-b06e-ac4b735a5a18</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;What I learn from your blog is essentially that I should be using isNullOrEmpty (the same thing everyone else here is saying).&amp;nbsp; I don&amp;#39;t have a need for the edge cases you mention, but it is good info to know about.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152263?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:22:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c22c33d4-8f6e-489a-b8ca-71060a0c0629</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;&lt;span&gt;You are correct in that isNullOrEmpty does return true in this case.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152262?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:21:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:52c9fcea-7480-4179-9fb7-55ec0dad2028</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;&lt;span&gt;You are correct in that isNullOrEmpty does return true in this case.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152261?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:21:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:304723d4-07fb-4228-bba5-7d7cb996f02c</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;You are correct in that isNullOrEmpty does return true in this case.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152260?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:17:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c55449a3-1f0a-4872-af45-7ecd6bac843a</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;And yet, within SH_ErrorGenertor length() did return 0.&amp;nbsp; Why does it sometimes return 0 and sometime return 1 for the same value?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152259?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 12:09:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f828a246-7a10-46af-8330-873d677d4c3f</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;I&amp;#39;m not looking for a string to be empty.... I&amp;#39;m looking to see if an array is empty.&amp;nbsp; Why would length(someArray) be 1 if there are no items in the array?&amp;nbsp; That doesn&amp;#39;t make any sense.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152252?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 07:47:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:969d0ccd-5ff5-463c-9d37-4b1df6325456</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;In this blog post, I try to cover how to check for empty data.&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://appian.rocks/2022/10/17/the-magic-of-null-checking/"&gt;https://appian.rocks/2022/10/17/the-magic-of-null-checking/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152246?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 05:54:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:858e6e50-6440-47e7-9dbd-db181041cdf8</guid><dc:creator>Harsha Sharma</dc:creator><description>&lt;p&gt;The expression for local!anyErrors in expression 2 checks if error is not null as well as its length. Though the local!errors is having 0 items yet as the function&amp;nbsp;length(&amp;quot;&amp;quot;) returns 1. So length will return true. Similarly behavior of isnull() can be understood from below.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;not(isnull({&amp;quot;&amp;quot;})) returns true&lt;br /&gt;not(isnull(&amp;quot;&amp;quot;)) returns false&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; length(&amp;quot;&amp;quot;)   /*returns true*/
not(isnull({&amp;quot;&amp;quot;})) /*returns true with a List of empty string*/
not(isnull(&amp;quot;&amp;quot;)) /*returns false with empty string*/&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Given the behavior and working of isnull() and length() the value for local!anyErrors in expression 2 seems fine. To properly check and correct the behavior as per your requirement I suggest you to either replace the local!anyErrors definition with a!isNotNullOrEmpty(local!errors) or simply use local!result.anyErrors.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;local!anyErrors: a!isNotNullOrEmpty(local!errors) or,
local!anyErrors: local!result.anyErrors /* Either of these*/

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152245?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 05:27:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d5df965a-1fc7-41bd-93c9-98a664b02dcc</guid><dc:creator>osanchea</dc:creator><description>&lt;p&gt;When you use index() or dot notation, the value returned is a variant. This can produce a different result when you use the length() function.&lt;/p&gt;
&lt;p&gt;To resolve this issue, create a map instead of a dictionary, because values stored in maps are not wrapped in a variant.&lt;/p&gt;
&lt;p&gt;Additionally, according to the Appian documentation:&lt;br /&gt;When you pass an empty array to the isnull() function, it returns false. To check whether an empty list is null, use the a!isNullOrEmpty() function instead.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1761888392486v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152244?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 04:36:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f9129b5b-b9f3-43d2-bb31-65092b08bbff</guid><dc:creator>Shubham Aware</dc:creator><description>&lt;p&gt;Appian treats lists with empty strings as having length, but they cannot be indexed.&lt;br /&gt;Use a!isNullOrEmpty() to check for real errors instead of length().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152243?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 00:51:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e844cb66-f8f6-4ba6-9be9-2505990f44e5</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;Actually, your scenario does not faithfully represent my code above.&amp;nbsp; You are, indeed, using an array of variant by specifying {} without any qualification.&amp;nbsp; I explicitly cast my data to List&amp;lt;string&amp;gt; (see first code segment above).&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think this will repro without using 2 expression rules.&amp;nbsp; As I showed in my example, within the first expression rule, it does, rightly, know the array is empty.&amp;nbsp; It&amp;#39;s not until it is returned to the calling expression rule that the weirdness ensues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152242?ContentTypeID=1</link><pubDate>Thu, 30 Oct 2025 22:43:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a7a45edc-682b-497d-bc8e-d2581dca4b37</guid><dc:creator>osanchea</dc:creator><description>&lt;p&gt;I&amp;rsquo;ve tried to replicate your case, and it seems that when you&amp;rsquo;re indexing the value &amp;ldquo;local!result.error&amp;rdquo;, it&amp;rsquo;s returning a list of variants. That&amp;rsquo;s why you&amp;rsquo;re getting the error you mentioned.&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1761864185504v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array with no items but length still &gt; 0</title><link>https://community.appian.com/thread/152241?ContentTypeID=1</link><pubDate>Thu, 30 Oct 2025 20:21:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c4bdb568-da22-4cd1-88bc-66c5883d65f7</guid><dc:creator>stevenh6272</dc:creator><description>&lt;p&gt;A small tweak shows the second expression sees the array as having 1 element.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!result: rule!SH_ErrorGenerator(),
  local!errors: local!result.errors,
  local!anyErrors: and(not(isnull(local!errors)), length(local!errors) &amp;gt; 0),
  {
    a: local!anyErrors,
    b: length(local!errors)
  }
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1761855635372v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But, of course, you cannot actually index that item.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!result: rule!SH_ErrorGenerator(),
  local!errors: local!result.errors,
  local!anyErrors: and(not(isnull(local!errors)), length(local!errors) &amp;gt; 0),
  {
    a: local!anyErrors,
    b: length(local!errors),
    c: local!errors[1]
  }
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1761855715135v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>