<?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>Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/discussions/f/rules/21530/getting-one-property-value-from-dictionary-based-upon-another-property-value</link><description>I have this expression rule and I need to get the value of one of the keys based upon whether another key property is true or false, I have this but doesn&amp;#39;t work: 
 
 To explain further: I would want to return the value &amp;quot;Green&amp;quot; from the key property color</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84152?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 15:08:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:100e5ebe-7ffb-4313-b3b6-35ad1725d8d3</guid><dc:creator>here2learn</dc:creator><description>&lt;p&gt;OK, I see what you mean now, thank you for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84148?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:30:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:77702a4b-3fb5-4db0-bb06-ae41bb12b6a5</guid><dc:creator>Josh</dc:creator><description>&lt;p&gt;The example you just posted works just fine for your desired outcome.&lt;/p&gt;
&lt;p&gt;I was saying you would need a looping function to filter out nulls in your first example if you were to use if(). The if() approach would result in &amp;quot;{&amp;quot;Green&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;Blue&amp;quot;}&amp;quot;. If you wanted just &amp;quot;{&amp;quot;Green&amp;quot;, &amp;quot;Blue&amp;quot;}&amp;quot;, you would need to get rid of that middle &amp;quot;&amp;quot; element. Here is that example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!myDictionary: {
    {
      item: 1,
      active: true,
      description: &amp;quot;Widget&amp;quot;,
      color: &amp;quot;Green&amp;quot;},
    {
      item: 2,
      active:false,
      description: &amp;quot;another&amp;quot;,
      color: &amp;quot;red&amp;quot;}
  },
  local!tempResults: if(toboolean(fn!index(local!myDictionary,&amp;quot;active&amp;quot;,&amp;quot;&amp;quot;)),
    fn!index(local!myDictionary,&amp;quot;color&amp;quot;,null), 
    &amp;quot;&amp;quot;
  ),
  reject(fn!isnull, local!tempResults)
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note: At the risk of over-simplification, think of reject() as a specialized a!forEach() in this instance.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84147?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:23:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:26745b08-2fc9-4ddf-b9fa-56e9ba0267a8</guid><dc:creator>here2learn</dc:creator><description>&lt;p&gt;Sure:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!myDictionary: {
    a!map(
      item: 1,
      active: true,
      description: &amp;quot;Widget&amp;quot;,
      color: &amp;quot;Green&amp;quot;
    ),
    a!Map(
      item: 2,
      active:false,
      description: &amp;quot;another&amp;quot;,
      color: &amp;quot;red&amp;quot;
    ),
    a!Map(
      item: 3,
      active:true,
      description: &amp;quot;another des&amp;quot;,
      color: &amp;quot;blue&amp;quot;
    )
  },
  index(local!myDictionary.color, where(local!myDictionary.active), {})
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When you mentioned that you would save&amp;nbsp;the results in a forEach() function, the above code now has two true items, in this instance, utilizing a forEach() would produce a list of {Green,Blue}. Is this correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84146?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:20:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:73809e67-2f3a-41a8-a53b-88e436a326d5</guid><dc:creator>Josh</dc:creator><description>&lt;p&gt;Can your expand your question or give an example? I&amp;#39;m not sure what you are asking.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84145?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:19:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:28f3f322-d22c-4ef5-a748-81be0483be9e</guid><dc:creator>here2learn</dc:creator><description>&lt;p&gt;&lt;em&gt;You could store this result and filter out the nulls using filter() or a!forEach(),&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could this be a test case (forEach()) &lt;strong&gt;IF&lt;/strong&gt; there were more than one true in the active property? Is this a correct assumption?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84144?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:11:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8d99031e-2082-4ab6-8f69-fa164152cbe9</guid><dc:creator>here2learn</dc:creator><description>&lt;p&gt;Great explanation with the bullet points. I was not aware you could use functions within the square brackets and the reason why I may have missed something simple as this, but now I know! Thank you for the help!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84143?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:00:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:702301d6-6253-4f1f-a7bb-442790bb54dd</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!myDictionary: {
    {
      item: 1,
      active: true,
      description: &amp;quot;Widget&amp;quot;,
      color: &amp;quot;Green&amp;quot;
    },
    {
      item: 2,
      active: false,
      description: &amp;quot;another&amp;quot;,
      color: &amp;quot;red&amp;quot;
    }
  },
  local!myDictionary.color[fn!wherecontains(true,fn!toboolean(local!myDictionary.active))]
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the result:&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/15/pastedimage1627566957942v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;...and here&amp;#39;s an explanation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you can address elements in an array using the square brackets&lt;/li&gt;
&lt;li&gt;...so we&amp;#39;re looking to extract all of the color attribute values - addressed using&amp;nbsp;local!myDictionary.color - where the corresponding &amp;#39;active&amp;#39; attribute is true...&lt;/li&gt;
&lt;li&gt;...so we use the function &amp;#39;wherecontains()&amp;#39; which returns the indices in an array that contain the the provided value. So, in our case,&amp;nbsp;fn!wherecontains(true,&amp;lt;the array of local!myDictionary.active&amp;gt;)&lt;/li&gt;
&lt;li&gt;the expression inside the square brackets returns the indices and is then used to return the values for the array that the square brackets are attached to&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hope this helps&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting One Property Value From Dictionary Based Upon Another Property Value</title><link>https://community.appian.com/thread/84142?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 14:00:11 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ccd3421a-fa26-449e-ae8b-6a7d776e6d2f</guid><dc:creator>Josh</dc:creator><description>&lt;p&gt;Close.&amp;nbsp;There are a couple of notes. You should use a!map() instead of dictionaries to help resolve typing mismatch errors. With a dictionary you are probably getting a compare error with a list of variant and boolean. so that line should be more like&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if(toboolean(fn!index(local!myDictionary,&amp;quot;active&amp;quot;,&amp;quot;&amp;quot;)),&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note: &amp;quot;if(predicate = true,&amp;quot; and &amp;quot;if(predicate,&amp;quot; are logically the same&lt;/p&gt;
&lt;p&gt;Line 15 will give you a boolean array of the indices where &amp;quot;active&amp;quot; is true, but wherever you return false, you will get &amp;quot;&amp;quot; returned, so your snippet would return {&amp;quot;Green&amp;quot;, &amp;quot;&amp;quot;}. You could store this result and filter out the nulls using filter() or a!forEach(), but&amp;nbsp;I would write this like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!myDictionary: {
    a!map(
      item: 1,
      active: true,
      description: &amp;quot;Widget&amp;quot;,
      color: &amp;quot;Green&amp;quot;
    ),
    a!Map(
      item: 2,
      active:false,
      description: &amp;quot;another&amp;quot;,
      color: &amp;quot;red&amp;quot;
    )
  },
  index(local!myDictionary.color, where(local!myDictionary.active), {})
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>