<?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>iterate over a map key</title><link>https://community.appian.com/discussions/f/general/37415/iterate-over-a-map-key</link><description>Hi Champs, 
 I have a map value having multiple key and value pair. Now I want to check for a value which exists in one or more key. So I guess the only way to do that is to iterate over the keys in the map. 
 How can I achieve the same. As of my knowledge</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: iterate over a map key</title><link>https://community.appian.com/thread/140085?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 14:29:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:57996122-95a1-460d-8a89-81b5d74b1a9f</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;remember that &lt;em&gt;&lt;strong&gt;a!keys()&lt;/strong&gt;&lt;/em&gt; grabs all keys (as a text array) in a particular dictionary, which you can grab into a local variable and then iterate over.&amp;nbsp; As Stefan pointed out, you can&amp;#39;t push new values into the existing map, but if (as your post implies) you only need to check which keys contain a certain value, then this should work fine.&amp;nbsp; It should work similarly to Tim&amp;#39;s suggested code except you wouldn&amp;#39;t need to hardcode your key values in the &amp;quot;local!definedKeys&amp;quot; variable, you&amp;#39;d just use a!keys() there pointed to your map variable.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: iterate over a map key</title><link>https://community.appian.com/thread/140072?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 10:02:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fb28ad28-6016-4b39-ad4c-7748df4f0ffd</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;No. As variables in Appian are immutable, you cannot update anything during iterations. But using some of the set functions, you can easily do this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: iterate over a map key</title><link>https://community.appian.com/thread/140068?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 09:23:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:70d84932-2b85-4d11-b5b9-dbc2ed32186d</guid><dc:creator>David Jimenez </dc:creator><description>&lt;p&gt;If you always have the same keys...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;local!key1: index(local!map, &amp;quot;key1&amp;quot;),&lt;br /&gt; local!key2: index(local!map, &amp;quot;key2&amp;quot;),&lt;br /&gt; local!key3: index(local!map, &amp;quot;key3&amp;quot;),&lt;br /&gt; &lt;br /&gt; local!int1: union(intersection(local!key1, local!key2),intersection(local!key1, local!key2)),&lt;br /&gt; local!int2: union(intersection(local!key1, local!key3),intersection(local!key1, local!key3)),&lt;br /&gt; local!int3: union(intersection(local!key2, local!key3),intersection(local!key2, local!key3)),&lt;/p&gt;
&lt;p&gt;local!int1 &amp;amp; &amp;quot;//&amp;quot; &amp;amp; local!int2 &amp;amp; &amp;quot;//&amp;quot; &amp;amp; local!int3&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: iterate over a map key</title><link>https://community.appian.com/thread/140066?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 08:23:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9cb2dd2d-9793-4417-8b6c-3bc873966315</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;If you define an array of your key names you can iterate over them with a nested a!forEach(). Example below, you can do what you want with the test and return value on the inner loop.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!map: {
    a!map(
      label: &amp;quot;Map 1&amp;quot;,
      key1: &amp;quot;A&amp;quot;,
      key2: &amp;quot;C&amp;quot;,
      key3: &amp;quot;C&amp;quot;
    ),
    a!map(
      label: &amp;quot;Map 2&amp;quot;,
      key1: &amp;quot;C&amp;quot;,
      key2: &amp;quot;A&amp;quot;,
      key3: &amp;quot;B&amp;quot;
    ),
    a!map(
      label: &amp;quot;Map 3&amp;quot;,
      key1: &amp;quot;C&amp;quot;,
      key2: &amp;quot;B&amp;quot;,
      key3: &amp;quot;C&amp;quot;
    )
  },
  local!definedKeys: { &amp;quot;key1&amp;quot;, &amp;quot;key2&amp;quot;, &amp;quot;key3&amp;quot; },
  a!forEach(
    items: local!map,
    expression: a!localVariables(
      local!innerMap: fv!item,
      a!forEach(
        items: local!definedKeys,
        expression: if(
          local!innerMap[fv!item] =&amp;quot;C&amp;quot;,
          fv!item,
          {}
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>