<?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>Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/discussions/f/general/8577/is-there-a-way-to-dynamically-add-a-new-element-to-a-dictionary</link><description>I&amp;#39;d like to at run time add new name value pair to a dictionary. Is this possible? Thanks. OriginalPostID-239395</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/76170?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 14:29:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9c8a80e3-93a8-4509-833c-9cf1c39a0ed7</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;You are welcome :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/76169?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 13:47:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:cba766a4-b027-459d-9654-6510d5332565</guid><dc:creator>paulg0001</dc:creator><description>&lt;p&gt;Wow Stefan, you never cease to amaze. Thank you for helping with this. As for the update, I am not an Administrator of our Appian systems. Things move slowly around here. Lots of red tape required but I will begin the process of requesting the update. For example: first qtr &amp;#39;20, upgraded from 18.2 to 19.4 (current). Grateful for 19.4. Thankful for your help, Sir.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/76162?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 06:24:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b117f5f9-758f-4062-9bfa-b482f373ba2d</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Why is an update no option? The new version includes to old functions as well.&lt;/p&gt;
&lt;p&gt;This is a quick solution. I am pretty sure there is a better one.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!values: {{ id:1, name:&amp;quot;alpha&amp;quot; },{ id:2, name:&amp;quot;bravo&amp;quot; },{ id:3, name:&amp;quot;charlie&amp;quot; }},
  reduce(
    updatecdt(_,_),
    cast(type!Dictionary, {}),
    a!forEach(
      items: local!values,
      expression: a!fromJson(
        substitute(
          a!toJson({tzqYx62_01_: fv!item.name}),
          &amp;quot;tzqYx62_01_&amp;quot;,
          fv!item.id
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/76159?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 16:12:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c2b4a4e8-c151-41a8-8e49-815b24c62bc9</guid><dc:creator>paulg0001</dc:creator><description>&lt;p&gt;Stefan, that would be wonderful, but I do not have the option to update to the new versions of the Dictionary Manipulation plugin. Is it possible to accomplish the same with your previous updatecdt / fromJson / toJson approach?&lt;/p&gt;
&lt;p&gt;There was another post where a contributor suggested incorporating reduce() with your recipe for updatecdt() but I do not know how to work in the correct syntax to accomplish the desired outcome.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/76156?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 15:04:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a275a8c3-abf3-4ee7-9a7f-3977b2b02890</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Update to the new versions of the Dictionary Manipulation plugin and use the code below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!values: {{ id:1, name:&amp;quot;alpha&amp;quot; },{ id:2, name:&amp;quot;bravo&amp;quot; },{ id:3, name:&amp;quot;charlie&amp;quot; }},
  createdictionary(
    local!values.id,
    local!values.name
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/76155?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 14:12:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4fbfd1a0-adda-4c0c-8ed5-d9fb30c205af</guid><dc:creator>paulg0001</dc:creator><description>&lt;p&gt;Stefan, I&amp;#39;ve executed&amp;nbsp;Shashanks code and it works great. Thank you for your contributions.&lt;/p&gt;
&lt;p&gt;How would you incorporate this approach within a foreach() where items is a list of dictionary and local!test output contains custom key:value pairs derived from each dictionary in the list?&lt;br /&gt;&lt;br /&gt;Ex: local!dictionaries: {{ id:1, name:&amp;quot;alpha&amp;quot; },{ id:2, &lt;span&gt;name:&lt;/span&gt;&amp;quot;bravo&amp;quot; }.{ id:3, &lt;span&gt;name:&lt;/span&gt;&amp;quot;charlie&amp;quot; }}&lt;/p&gt;
&lt;p&gt;local!test output: { alpha:1, bravo:2, charlie:3 }&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;with(
  local!test: {
    {
      id: 1,
      name: &amp;quot;test&amp;quot;
    }
  },
  local!newKeyValPair: a!fromJson(
    substitute(
      a!toJson(
        {
          tzqYx62_01_: ri!value
        }
      ),
      &amp;quot;tzqYx62_01_&amp;quot;,
      ri!key
    )
  ),
  local!updated: updatecdt(
    local!test,
    local!newKeyValPair
  ),
  local!updated
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/75225?ContentTypeID=1</link><pubDate>Tue, 07 Jul 2020 06:08:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:49f6bcf9-f693-4d49-bcc1-c7467a50dbb9</guid><dc:creator>warner jonn</dc:creator><description>&lt;p&gt;try this to &lt;a href="http://net-informations.com/python/ds/dictionary.htm"&gt;dictionary&lt;/a&gt;&lt;/p&gt;
&lt;pre class="lang-py prettyprint prettyprinted"&gt;&lt;code&gt;&lt;span class="pln"&gt;dictionary &lt;/span&gt;&lt;span class="pun"&gt;=&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="pun"&gt;{&lt;/span&gt;&lt;span class="pln"&gt;x&lt;/span&gt;&lt;span class="pun"&gt;:&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="pun"&gt;[]&lt;/span&gt;&lt;span class="pln"&gt; &lt;/span&gt;&lt;span class="kwd"&gt;for&lt;/span&gt;&lt;span class="pln"&gt; x &lt;/span&gt;&lt;span class="kwd"&gt;in&lt;/span&gt;&lt;span class="pln"&gt; names&lt;/span&gt;&lt;span class="pun"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37849?ContentTypeID=1</link><pubDate>Sun, 09 Oct 2016 13:41:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5f17186b-9a48-46fb-90db-534790159381</guid><dc:creator>Shashank</dc:creator><description>@briank .. No worries .. Glad that it was helpful !!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37848?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 18:44:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:db7308ab-8e7e-442c-9df1-751aa2ee0ed9</guid><dc:creator>briank538</dc:creator><description>Thanks everyone.  Shashankb/Stefanh791, your solution worked like a charm.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37843?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 15:05:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fdd74419-b177-4c57-b462-957edd920108</guid><dc:creator>Stefan Helzle</dc:creator><description>You are welcome :-)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37841?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 13:32:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:93081c4e-c516-4835-9264-b5a2c9ca92d0</guid><dc:creator>Shashank</dc:creator><description>with(&lt;br /&gt;  local!test: {&lt;br /&gt;    {&lt;br /&gt;      id: 1,&lt;br /&gt;      name: &amp;quot;test&amp;quot;&lt;br /&gt;    }&lt;br /&gt;  },&lt;br /&gt;  local!newKeyValPair: a!fromJson(&lt;br /&gt;    substitute(&lt;br /&gt;      a!toJson(&lt;br /&gt;        {&lt;br /&gt;          tzqYx62_01_: ri!value&lt;br /&gt;        }&lt;br /&gt;      ),&lt;br /&gt;      &amp;quot;tzqYx62_01_&amp;quot;,&lt;br /&gt;      ri!key&lt;br /&gt;    )&lt;br /&gt;  ),&lt;br /&gt;  local!updated: updatecdt(&lt;br /&gt;    local!test,&lt;br /&gt;    local!newKeyValPair&lt;br /&gt;  ),&lt;br /&gt;  local!updated&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37840?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 13:31:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a26174db-d0a4-440a-a111-d81cc3c688fb</guid><dc:creator>Shashank</dc:creator><description>@stefanh , Thanks a lot for your valuable input , I have updated the above code with your snippet . It worked like a charm !!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37839?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 12:13:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dbcc3b41-7fab-49bd-b46c-1c9754707acf</guid><dc:creator>kondetiv</dc:creator><description>sorry misunderstood !&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37838?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 11:40:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:678e59a5-2f8b-4925-ac42-1f99a5beb270</guid><dc:creator>kondetiv</dc:creator><description>output for the above code :- &lt;br /&gt;&lt;br /&gt;type&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List of Dictionary&lt;br /&gt;2 items&lt;br /&gt;Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;[label:firstName,value:kondeti]; [label:lastName,value:venkat]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37837?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 11:39:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f4580f9f-eb2e-4b3d-b8a2-3e3a54a58991</guid><dc:creator>kondetiv</dc:creator><description>here is the small code snippet i tried. Not sure how far it may be helpful for you.  &lt;br /&gt;&lt;br /&gt;with(&lt;br /&gt;  local!dictionary:{{label:&amp;quot;firstName&amp;quot;,value:&amp;quot;kondeti&amp;quot;}},&lt;br /&gt;  &lt;br /&gt;  {&lt;br /&gt;    append(local!dictionary,{label:&amp;quot;lastName&amp;quot;,value:&amp;quot;venkat&amp;quot;}),&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37836?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 11:34:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9e58e3be-69b9-43c3-ae96-9a89067dbdd8</guid><dc:creator>Stefan Helzle</dc:creator><description>The problem is that updatecdt does not allow dynamic field names. But if you add&lt;br /&gt;&lt;br /&gt;a!fromJson(substitute(a!toJson({tzqYx62_01_:ri!value}), &amp;quot;tzqYx62_01_&amp;quot;, ri!key)) &lt;br /&gt;&lt;br /&gt;to the above code, even that is possible. It creates a dictionary with a fixed field name and converts it to JSON. Then it replaces the field name in the JSON string to the desired field name and converts it back to an Appian dictionary.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37835?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 11:21:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d7985660-5611-4af7-a9e7-dcc65e8b1216</guid><dc:creator>Shashank</dc:creator><description>Did a small test , not sure how far it may be helpful , but might be a start : &lt;br /&gt;&lt;br /&gt;with(&lt;br /&gt;  local!test : {{id : 1, name : &amp;quot;test&amp;quot;}},&lt;br /&gt;  local!updated : updatecdt(local!test,{newField : &amp;quot;myNew&amp;quot;}),&lt;br /&gt;  &lt;br /&gt;  local!updated&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37834?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 11:10:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a720ec3f-087c-468c-bf71-c3cde7e06c12</guid><dc:creator>Shashank</dc:creator><description>@briank Hi , did you have a chance to look at the following shared component &lt;br /&gt;&lt;br /&gt;https://forum.appian.com/suite/tempo/records/item/lMBCLGOdlMUpdGVqW3dQaIKmclBmvvNEj8vu_cjb7T-5YiPr4Fu8ly5Yj1s09uenE4RYzA8zKyx7eiUhu-iLnNiL_yNHr1dalWMFghiqrZpWgaUrg/view/summary &lt;br /&gt;&lt;br /&gt;Please have a look at the updatecdt , it might be helpful in adding a new field to your cdt&lt;br /&gt;&lt;br /&gt;Thanks&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is there a way to *dynamically* add a new element to a dictionary?</title><link>https://community.appian.com/thread/37833?ContentTypeID=1</link><pubDate>Sat, 08 Oct 2016 09:58:48 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:90d56488-3bc0-4e8d-a09e-fa185d8f4d11</guid><dc:creator>Nagashankar Nallavalli</dc:creator><description>@ briank please find the below link &lt;a href="https://forum.appian.com/suite/help/16.3/Expressions.html#dictionaries"&gt;forum.appian.com/.../Expressions.html&lt;/a&gt;&lt;br /&gt;hope this is helpful to you&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>