<?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>How to access CDT field by number ?</title><link>https://community.appian.com/discussions/f/data/23808/how-to-access-cdt-field-by-number</link><description>Hi, 
 I&amp;#39;m surprised to have to ask this question, but could you tell me how to access the value of a CDT field giving a number please ? 
 I would need to use this kind of code : 
 local!value: field(local!vehicle, 1) /* where &amp;quot;1&amp;quot; is the first field of</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to access CDT field by number ?</title><link>https://community.appian.com/thread/91519?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 11:52:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fd9fa549-cb8f-47d7-ad3d-ee3801ed6cb7</guid><dc:creator>cedric02</dc:creator><description>&lt;p&gt;This does not work, but this workaround works (with [1]) :&lt;/p&gt;
&lt;p&gt;because apparently the queryEntity returns a list even if there is only one row in the data returned.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!vehicle: a!flatten(rule!CJT2_GetVehiclesWithFilters(id: 1).data),
  local!keys: a!keys(local!vehicle[1]),
  local!keys
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks a lot for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access CDT field by number ?</title><link>https://community.appian.com/thread/91515?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 11:13:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2a376427-4ef9-420d-b20c-b279bfdfc3af</guid><dc:creator>ajhick</dc:creator><description>&lt;p&gt;It&amp;#39;s a bit of a guess but try this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!vehicle: a!flatten(rule!CJT2_GetVehiclesWithFilters(id: 1).data),
  local!keys: a!keys(local!vehicle),
  local!keys
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access CDT field by number ?</title><link>https://community.appian.com/thread/91514?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 11:07:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ec42ae41-1db3-444c-83e8-24f7775e35c2</guid><dc:creator>cedric02</dc:creator><description>&lt;p&gt;I did not know that we could iterate through the keys.&amp;nbsp;So&amp;nbsp;if I can use only keys, that&amp;#39;s&amp;nbsp;perfect for me.&lt;/p&gt;
&lt;p&gt;Your code works with a Map but when I try with a queryEntity result (data), it does not work. Am I missing something ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;ERROR :&amp;nbsp;&lt;span style="color:#ff0000;"&gt;Expression evaluation error at function a!keys [line 4]: The passed parameter(s) are of the wrong type. Received the type List of Variant.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!vehicle: rule!CJT2_GetVehiclesWithFilters(id: 1).data,
  local!keys: a!keys(local!vehicle),
  local!keys
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access CDT field by number ?</title><link>https://community.appian.com/thread/91512?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 10:54:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:42199b20-3514-4a29-b763-b0a853054f2d</guid><dc:creator>ajhick</dc:creator><description>&lt;p&gt;Ok, I&amp;#39;m not sure I fully understand but if you&amp;#39;re comparing all fields you don&amp;#39;t need the field numbers, you can just iterate through the keys. Also, if you&amp;#39;re not comparing all fields and the field numbers are required I feel like field names are more robust as someone could add a column towards the start of a table and break your numbering.&lt;/p&gt;
&lt;p&gt;Again, I&amp;#39;m not across your exact use case but something is telling me there is a better way to achieve what you&amp;#39;re after.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access CDT field by number ?</title><link>https://community.appian.com/thread/91511?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 10:40:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7c063679-c097-4b40-8a7b-4ac7048ed29f</guid><dc:creator>cedric02</dc:creator><description>&lt;p&gt;That&amp;#39;s great Ajhick, it is exactly what I was looking for.&lt;/p&gt;
&lt;p&gt;I was looking for such a way because sometimes,&amp;nbsp;for&amp;nbsp;business need, I have to compare all the&amp;nbsp;fields accross the rows of a CDT.&lt;/p&gt;
&lt;p&gt;For example, keeping the common values accross many lines.&lt;/p&gt;
&lt;p&gt;Today, I compare theses lines using the fieldnames, but because the table in DB can evolve, using the fieldnames&amp;nbsp;can introduce some lake of maintenability.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;With the method you&amp;#39;ve suggested me, if one day,&amp;nbsp;somebody will add a field in the Table/CDT, the code will continue to work.&lt;/p&gt;
&lt;p&gt;(the developpers will not have to look in all Appian&amp;nbsp;ER to ad this new field)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access CDT field by number ?</title><link>https://community.appian.com/thread/91510?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 10:24:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3131bb6e-b65a-4257-a15f-c2d124648d5a</guid><dc:creator>ajhick</dc:creator><description>&lt;p&gt;Never seen this use case but give this a go. Just out of interest, why access the field by a number? Not saying it&amp;#39;s wrong I&amp;#39;ve just never come across a need to do this.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: {
    id: 31,
    make: &amp;quot;Ford&amp;quot;,
    model: &amp;quot;F150&amp;quot;,
    year: 2019,
    country: &amp;quot;Australia&amp;quot;,
    insured: true
  },
  local!keys: a!keys(local!data),
  local!fieldNumbersToDisplay: {2,3,4,6}, /*Can play around with this for different field numbers*/
  local!fieldsToDisplay: index(
    local!keys,
    local!fieldNumbersToDisplay,
    {}
  ),
  concat(
    a!forEach(
      items: local!fieldsToDisplay,
      expression: concat(
        proper(fv!item),
        &amp;quot;: &amp;quot;,
        index(
          local!data,
          fv!item,
          {}
        ),
        if(
          fv!isLast,
          {},
          &amp;quot; | &amp;quot;
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>