<?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>How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/discussions/f/rules/19514/how-to-reject-values-in-a-cdt-array-on-the-basis-of-a-condition</link><description>Hi All, 
 I want to reject values in a CDT array on the basis of a condition. 
 For ex - I have a CDT array of type, suppose, type!someType(a,b), where a and b are fields in CDT. Now, My array looks like below: 
 { 
 type!someType(a: 1, b: null) 
 type</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76341?ContentTypeID=1</link><pubDate>Tue, 08 Sep 2020 12:24:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:64417976-bc34-4b7e-a326-44f58eb6ba64</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;FYI, I&amp;#39;ve noticed this before as well, and more recently I&amp;#39;ve figured out that wrapping the entire &lt;em&gt;a!forEach()&lt;/em&gt; statement in &lt;strong&gt;&lt;em&gt;a!flatten()&lt;/em&gt;&lt;/strong&gt; also handles this scenario (with much less bad taste in the back of my mouth than using the old looping functions).&lt;/p&gt;
&lt;p&gt;(In fact, I was considering including it in my answer above, but I thought for the moment it might be better to not over-complicate things.. now i&amp;#39;m not so sure)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76328?ContentTypeID=1</link><pubDate>Mon, 07 Sep 2020 10:24:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:20f0efdf-8c7b-4d39-b823-ae300d81ea3f</guid><dc:creator>varunkumarb0001</dc:creator><description>&lt;p&gt;&lt;a href="/members/chris"&gt;Chris&lt;/a&gt;&lt;a href="/members/mikes0011"&gt;Mike Schmitt&lt;/a&gt;&lt;a href="/members/stefanh791"&gt;Stefan Helzle&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks everyone for the elaborate responses. The solution provided worked.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76319?ContentTypeID=1</link><pubDate>Sat, 05 Sep 2020 12:36:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3549c5d6-8ec0-432d-ae97-511a717d7b1b</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;May I indicate one issue with the foreach-filter habit. In case no item matches the condition, the created list is a list of empty lists {{}, {}, {}, ...}. This can break any subsequent code and can be a pain to debug. This is why I still recommend&amp;nbsp;the &amp;quot;old&amp;quot; looping functions filter() and reject() and asked Appian to come up with new filter functions similar to a!foreach().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76312?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 17:30:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8a7d677d-1951-45ca-a2a3-dd949ea1c468</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;wow/ouch ;-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76311?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 16:37:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a3f7347b-d739-4cb4-9241-0149586f69e7</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;You may!&amp;nbsp; I agree with the a!forEach() replacement.&amp;nbsp; Still kicking the bad apply() habit..&amp;nbsp; Heck, we still have doForEach in a few older Portal PMs circa 2010 ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76309?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 15:52:05 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:be991b04-3a59-47e0-8645-b49c4aae8b49</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;a!forEach()&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;&lt;/em&gt; handles this more gracefully, IMHO, and allows us to skip the awful deprecated &amp;quot;apply()&amp;quot; function.&lt;/p&gt;
&lt;p&gt;(If I may borrow your original code..)&lt;br /&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!data: {
    {a: 1, b: null},
    {a: null, b: null},
    {a: null, b: 1},
    {a: 1, b: 2},
    {a: 2, b: null}
  },
  
  a!forEach(
    items: local!data,
    expression: if(
      isnull(fv!item.a),
      {},
      fv!item
    )
  )

  /*index(*/
    /*local!data,*/
    /*wherecontains(*/
      /*reject(*/
        /*fn!isnull,*/
        /*local!data.a*/
      /*),*/
      /*apply(fn!tointeger,local!data.a)*/
    /*)*/
  /*)*/
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to reject values in a CDT array on the basis of a condition?</title><link>https://community.appian.com/thread/76308?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 15:35:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:99c8b4e8-6908-4ad6-833e-6d1d9e0416c6</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Try something like this.&amp;nbsp; Note in the wherecontains() you may have to change the apply(fn!tointeger..) to match your data type, as wherecontains() is type-sensitive.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;a!localVariables(
  local!data: {
    {a: 1, b: null},
    {a: null, b: null},
    {a: null, b: 1},
    {a: 1, b: 2},
    {a: 2, b: null}
  },
  
  index(
    local!data,
    wherecontains(
      reject(
        fn!isnull,
        local!data.a
      ),
      apply(fn!tointeger,local!data.a)
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>