<?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>saving array into the field of an array cdt</title><link>https://community.appian.com/discussions/f/general/18630/saving-array-into-the-field-of-an-array-cdt</link><description>I have a rule input of type cdt array. What I want to do is to add a list of values to one of the fields by looping through another list, something like in the example below. 
 a!save( ri!test.user_name, a!forEach( items: {1,2}, expression: &amp;quot;hey&amp;quot; ) )</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: saving array into the field of an array cdt</title><link>https://community.appian.com/thread/73361?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 01:33:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b12b47ff-e4d1-4add-98c8-d244ae7b9b64</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;if the CDT array is starting out empty, you will need to do something to instantiate its size, regardless of what else you do I think.&amp;nbsp; I mean, you could always manually construct a JSON string that would translate into roughly your CDT dictionary and then save that result back into the CDT, but I don&amp;#39;t see that significantly deviating from the construct of looping over a constructor.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note, I think you don&amp;#39;t have to actually call the &amp;quot;type!&amp;quot; constructor itself for each item in the loop - you would need only set the property that agrees with the CDT property you want; the rest would be taken care of by the typecasting that happens automatically during the save.&amp;nbsp; If that&amp;#39;s still not sufficient, then I&amp;#39;m kinda out of ideas.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: saving array into the field of an array cdt</title><link>https://community.appian.com/thread/73360?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 00:58:47 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:96f56d6a-33b5-4f85-b3c6-1411d842a28e</guid><dc:creator>Jose H.</dc:creator><description>&lt;p&gt;Hey Mike, thanks for the reply. I know your solution would work in the case that ri!test already has values in it. But in my case the array is empty.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I know I could have gone the route of looping through a list, creating a type constructor and appending to my ri!test&amp;nbsp;&lt;/p&gt;
&lt;p&gt;save(ri!test, foreach(items: list of values, expression: append(ri!test, type constructor with values)). However, for some weird requirement, I&amp;#39;m not allowed to do that, which is why I was trying to do it that other way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: saving array into the field of an array cdt</title><link>https://community.appian.com/thread/73359?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 00:48:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1a3ad32e-8efd-4ced-bcd2-c1b1a72dbc6c</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I&amp;#39;m a little unclear on some assumptions you&amp;#39;re making here - for example where does the &amp;quot;items: {1, 2}&amp;quot; list come from?&lt;/p&gt;
&lt;p&gt;What you have already written will save, over the entire array of ri!test, a list of &amp;quot;hey&amp;quot; text values for every &amp;quot;item&amp;quot; you iterate over.&amp;nbsp; Apparently this saves this into each member of the array.&amp;nbsp; I wouldn&amp;#39;t have been sure without testing, but I&amp;#39;m not terribly surprised - Appian does certain array/set operations a bit unintuitively sometimes.&lt;/p&gt;
&lt;p&gt;So instead, if&amp;nbsp; we assume that your ri!test is starting with 2 members of the array and you want to save the value &amp;quot;hey&amp;quot; into both username fields, then you would so something more like&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;saveInto: {
  a!forEach(
    ri!test,
    a!save(
      fv!item.user_name,
      &amp;quot;hey &amp;quot; &amp;amp; fv!index  /* this would make the user_name populate with &amp;quot;hey 1&amp;quot;, &amp;quot;hey 2&amp;quot;, etc */
    )
  )
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>