<?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>Map with variable key</title><link>https://community.appian.com/discussions/f/general/23723/map-with-variable-key</link><description>Is it somehow possible to create a map or dictionary using variables for the keys? For example, is there some way for me to do something like a!map(localvar1:local!var2) to make a user generated map? Or maybe use a foreach loop over a 2d array to convert</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/129154?ContentTypeID=1</link><pubDate>Thu, 08 Feb 2024 02:51:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1b475763-22f1-467b-9405-20389d2958ec</guid><dc:creator>ChamindaF</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I know its late ... This also works ,&lt;/p&gt;
&lt;p&gt;a!localVariables(&lt;br /&gt; local!keys: { &amp;quot;keyOne&amp;quot;, &amp;quot;keyTwo&amp;quot;, &amp;quot;keyThree&amp;quot; },&lt;br /&gt; local!values: { 117, &amp;quot;Appian&amp;quot;, now() },&lt;/p&gt;
&lt;p&gt;a!update(&lt;br /&gt; data: a!map(),&lt;br /&gt; index: local!keys,&lt;br /&gt; value: local!values&lt;br /&gt; )&lt;br /&gt; &lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;output :&lt;/p&gt;
&lt;div class="FieldLayout---field_layout FieldLayout---margin_below_standard FieldLayout---margin_above_none FieldLayout---inColumnArrayLayout"&gt;
&lt;div class="FieldLayout---input_below"&gt;
&lt;div class="SideBySideGroup---side_by_side SideBySideGroup---default_direction SideBySideGroup---top"&gt;
&lt;div class="SideBySideItem---flex_item SideBySideItem---default_direction SideBySideItem---sparse SideBySideItem---minimize" data-padding-left="0" data-padding-right="-20" data-stacked="false"&gt;
&lt;div class="FieldLayout---field_layout FieldLayout---margin_below_none FieldLayout---margin_above_none FieldLayout---inSideBySideItem FieldLayout---inMinimizedSideBySideItem FieldLayout---inColumnArrayLayout"&gt;
&lt;div class="FieldLayout---input_below"&gt;
&lt;div class=""&gt;
&lt;p class="ParagraphText---richtext_paragraph ParagraphText---default_direction ParagraphText---align_start ParagraphText---inMinimizedSideBySideItem elements---global_p" data-testid="ParagraphText-paragraph"&gt;&lt;strong class="StrongText---richtext_strong"&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="FieldLayout---field_layout FieldLayout---margin_below_none FieldLayout---margin_above_none FieldLayout---inColumnArrayLayout"&gt;
&lt;div class="FieldLayout---input_below"&gt;
&lt;div class="SideBySideGroup---side_by_side SideBySideGroup---default_direction SideBySideGroup---bottom"&gt;
&lt;div class="SideBySideItem---flex_item SideBySideItem---default_direction SideBySideItem---minimize appian-context-last-in-list" data-padding-left="0" data-padding-right="0" data-stacked="false"&gt;
&lt;div class="FieldLayout---field_layout FieldLayout---margin_below_none FieldLayout---margin_above_none FieldLayout---inSideBySideItem FieldLayout---inMinimizedSideBySideItem FieldLayout---inColumnArrayLayout"&gt;
&lt;div class="FieldLayout---input_below"&gt;
&lt;div class="RadioSelect---choice_group RadioSelect---compact"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="ContentLayout---content_layout ContentLayout---flush"&gt;
&lt;div class="SelectableTree---selectableTree SelectableTree---allow_text_highlighting appian-context-ux-mouse-focus" data-appian-ux-mouse-focus=""&gt;
&lt;ul class="SelectableTree---treeContainer SelectableTree---children"&gt;
&lt;li class="SelectableTreeNode---selectableTreeNode SelectableTreeNode---open SelectableTreeNode---root SelectableTreeNode---allow_text_highlighting"&gt;
&lt;div class="SelectableTreeNode---inline SelectableTreeNode---openCloseLink"&gt;&lt;/div&gt;
&lt;span&gt;&lt;span class="CollapsibleOutputNode---print_non_value"&gt;Map&lt;/span&gt;&lt;/span&gt;
&lt;ul class="SelectableTreeNode---componentConfigParam"&gt;&lt;/ul&gt;
&lt;ul class="SelectableTreeNode---nonComponentConfigParam"&gt;
&lt;li class="SelectableTreeNode---selectableTreeNode SelectableTreeNode---leaf SelectableTreeNode---open SelectableTreeNode---allow_text_highlighting"&gt;&lt;span&gt;&lt;span class="CollapsibleOutputNode---print_key"&gt;keyOne&lt;/span&gt;&lt;span class="CollapsibleOutputNode---print_value"&gt;117&lt;/span&gt;&lt;span class="CollapsibleOutputNode---print_element_type"&gt;(Number (Integer))&lt;/span&gt;&lt;/span&gt;
&lt;ul class="SelectableTreeNode---componentConfigParam"&gt;&lt;/ul&gt;
&lt;ul class="SelectableTreeNode---nonComponentConfigParam"&gt;&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="SelectableTreeNode---selectableTreeNode SelectableTreeNode---leaf SelectableTreeNode---open SelectableTreeNode---allow_text_highlighting"&gt;&lt;span&gt;&lt;span class="CollapsibleOutputNode---print_key"&gt;keyTwo&lt;/span&gt;&lt;span class="CollapsibleOutputNode---print_value"&gt;&amp;quot;Appian&amp;quot;&lt;/span&gt;&lt;span class="CollapsibleOutputNode---print_element_type"&gt;(Text)&lt;/span&gt;&lt;/span&gt;
&lt;ul class="SelectableTreeNode---componentConfigParam"&gt;&lt;/ul&gt;
&lt;ul class="SelectableTreeNode---nonComponentConfigParam"&gt;&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="SelectableTreeNode---selectableTreeNode SelectableTreeNode---leaf SelectableTreeNode---open SelectableTreeNode---allow_text_highlighting"&gt;&lt;span&gt;&lt;span class="CollapsibleOutputNode---print_key"&gt;keyThree&lt;/span&gt;&lt;span class="CollapsibleOutputNode---print_value"&gt;2/8/2024 2:46 AM GMT+00:00&lt;/span&gt;&lt;span class="CollapsibleOutputNode---print_element_type"&gt;(Date and Time)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/119940?ContentTypeID=1</link><pubDate>Thu, 28 Sep 2023 17:36:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6518bb3b-87b4-4a81-baaf-bbfa27f0657e</guid><dc:creator>Alex Boerescu</dc:creator><description>&lt;p&gt;Hi, I know it&amp;#39;s late, but I thought it&amp;#39;d be good to capture the response here.&lt;/p&gt;
&lt;p&gt;You could use reduce with merge to achieve the desired outcome - not sure if all functions were available at the time you asked.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
&amp;#160; local!keys: { &amp;quot;keyOne&amp;quot;, &amp;quot;keyTwo&amp;quot;, &amp;quot;keyThree&amp;quot; },
&amp;#160; local!values: { 117, &amp;quot;Appian&amp;quot;, now() },
&amp;#160; reduce(
&amp;#160; &amp;#160; a!update,
&amp;#160; &amp;#160; a!map(),
&amp;#160; &amp;#160; merge(local!keys, local!values)
&amp;#160; )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Kudos to &lt;a href="/members/dionne.obrien"&gt;Dionne OBrien&lt;/a&gt; for the coming up with the solution!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91124?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:38:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9f3d7237-8fa3-401c-89a5-91ae4cfface8</guid><dc:creator>Marco</dc:creator><description>&lt;p&gt;Works perfectly. Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91123?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:38:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ed0dd935-b040-42f9-a510-15c3a88fd73b</guid><dc:creator>Marco</dc:creator><description>&lt;p&gt;Yeah, that&amp;#39;s what I was referring to&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91121?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:18:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a312da97-42ce-48d1-8bbc-f6409c7701fe</guid><dc:creator>ajhick</dc:creator><description>&lt;p&gt;Ooohhh. Yeah, I&amp;#39;ve never used or seen that either.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91118?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:15:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b3e13aac-adff-43b8-8559-2317c194a599</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I take that back - i think Marco is referring to the &amp;quot;Attributes&amp;quot; functionality provided within Group Types (which I&amp;#39;ve never used or seen used anywhere), but where the attributes of which are &lt;a href="https://docs.appian.com/suite/help/21.4/Group_Types.html#group-type-attributes"&gt;totally arbitrary&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91117?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:09:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7235df83-2261-438d-8f54-57eda7910fad</guid><dc:creator>ajhick</dc:creator><description>&lt;p&gt;Let me know how you go. But I would agree with Mike above. The solution I&amp;#39;ve proposed is only needed if the keys are unknown and attributes of groups is a known thing. Unless I&amp;#39;m misunderstanding your use case I don&amp;#39;t believe my solution is required.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91116?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:05:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e31fbe5b-c970-4331-a22c-ff9bd82b0825</guid><dc:creator>Marco</dc:creator><description>&lt;p&gt;That at least LOOKS like what I need. Gonna have to try it out to know for sure!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91112?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 22:00:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:005b1270-a31a-4ee0-acb6-45c1c50288db</guid><dc:creator>ajhick</dc:creator><description>&lt;p&gt;Hi Marco,&lt;/p&gt;
&lt;p&gt;The only way I&amp;#39;ve found of doing this is utilising JSON. Is below sort of what you&amp;#39;re looking for?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!keys: {
    &amp;quot;keyOne&amp;quot;,
    &amp;quot;keyTwo&amp;quot;,
    &amp;quot;keyThree&amp;quot;
  },
  local!values: {
    117,
    &amp;quot;Appian&amp;quot;,
    now()
  },
  local!keysAsJson: concat(
    &amp;quot;{&amp;quot;,
    a!forEach(
      items: local!keys,
      expression: concat(
        char(34),
        fv!item,
        char(34),
        &amp;quot;:&amp;quot;,
        char(34),
        char(34),
        if(
          fv!isLast,
          {},
          &amp;quot;,&amp;quot;
        )
      )
    ),
    &amp;quot;}&amp;quot;
  ),
  local!keysAsDictionary: a!fromJson(local!keysAsJson),
  reduce(
    a!update,
    local!keysAsDictionary,
    merge(
      local!keys,
      local!values
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91110?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 21:42:26 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:17de6f4c-a419-4093-9f62-42c739120960</guid><dc:creator>Marco</dc:creator><description>&lt;p&gt;I was wanting to use a!setGroupAttributes to make an interface that sets attributes on groups. The function requires a dictionary of attributes to set them and ideally I&amp;#39;d like the interface to allow one to set both the attribute names and values.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Map with variable key</title><link>https://community.appian.com/thread/91109?ContentTypeID=1</link><pubDate>Tue, 15 Feb 2022 21:37:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:701e5d65-d8f0-459d-b005-0817528adf03</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;AFAIK there isn&amp;#39;t&amp;nbsp;any way to define the key within a!map() dynamically like this.&amp;nbsp; This sounds like a situation I would utilize the database to maintain dynamically defined key-value pairs, where the user can enter both and you can reference them where you need via a!queryEntity().&lt;/p&gt;
&lt;p&gt;What is the use case?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>