<?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 inside a CDT</title><link>https://community.appian.com/discussions/f/best-practices/19698/iterate-inside-a-cdt</link><description>I have the following code: 
 a!localVariables( local!a: { 1,2 }, local!b: { 3, 4, 5 }, a!forEach( items: local!a, expression: &amp;#39;type!{urn:com:appian:types:XZY}Employee&amp;#39;( ID: fv!item, Value: fv!item, Field: a!foreach (items:local!b[fv!index], expression</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Iterate inside a CDT</title><link>https://community.appian.com/thread/76982?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2020 12:56:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8f7e6570-77a4-4405-8f6e-5b9c41fffd84</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Ok, understood.&lt;/p&gt;
&lt;p&gt;So, you&amp;#39;ll need to nest your a!forEach() loops. The outer one will select a value from local!a. You need to hold that value as a local!variable to be used in the inner loop:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!a: { 1,2 },
  local!b: { 3, 4, 5 },
  a!forEach(
    items: local!a,
      expression:  with(
        local!temp: fv!item,
        a!forEach(
        items: local!b,
        expression: &amp;#39;type!{urn:com:appian:types:XZY}Employee&amp;#39;(
          ID: local!temp,
          value: local!temp,
          field: fv!item
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Iterate inside a CDT</title><link>https://community.appian.com/thread/76981?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2020 12:11:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6146127c-1a38-4fff-80ac-70a5e0651bb9</guid><dc:creator>catalinp0002</dc:creator><description>&lt;p&gt;Both are arrays, think local!a&amp;nbsp;as {1,2,3,4}, not just 1 value. I&amp;#39;ve enhanced the question with this particular mention&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Iterate inside a CDT</title><link>https://community.appian.com/thread/76980?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2020 11:57:11 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:92da43ad-8fee-40f7-879a-b1c047827ada</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;You need to do this the other way around. Iterate over the local!b list:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
local!a: { 1 },
local!b: { 3, 4, 5 },
a!forEach(
items: local!b,
expression: &amp;#39;type!{urn:com:appian:types:XZY}Employee&amp;#39;(
ID: local!a,
Value: local!a,
Field: fv!item
)
)
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That should result in a list of type &amp;#39;Employee&amp;#39; with the fields set as required.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>