<?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 it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/discussions/f/general/25351/is-it-possible-to-fetch-a-cdt-field-by-numerical-index</link><description>Hi all, 
 I want to get fields in a CDT based on their numerical index, i.e. if I have a CDT like: 
 
 
 
 
 
 
 
 
 
 
 
 
 {&amp;#39;type!{urn:com:appian:types:TEST}TEST_Employee&amp;#39;(&amp;#39;firstName&amp;#39;: &amp;quot;Frank&amp;quot;, &amp;#39;secondName&amp;#39;: &amp;quot;Smith&amp;quot;, &amp;#39;age&amp;#39;: 29)} 
 To get the first field</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98639?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 15:08:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1fa47f2d-b98a-43e5-8981-3c8e2f24738c</guid><dc:creator>Mike Schmitt</dc:creator><description>[quote userid="34855" url="~/discussions/f/general/25351/is-it-possible-to-fetch-a-cdt-field-by-numerical-index/98632#98632"]How would I keep this persisted in a key-value fashion? [/quote]
&lt;p&gt;You can do pretty much whatever you want if you use an expression rule, FWIW &lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f60e.svg" title="Sunglasses"&gt;&amp;#x1f60e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The beauty of that is, you can design an expression rule using a &amp;quot;black box&amp;quot; approach, such that you can start out with hardcoded or even &amp;quot;faked&amp;quot; values, and if/when you decide to shift to a DB-backed approach, you can simply update that expression rule to do whatever internal querying it needs to do, in order to return the same values based on the input passed in.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98635?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 13:17:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:858f1d8e-2f21-457f-b9f6-43af0cefc62a</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;If you plan to persist this, go with a CDT and add a primary key field.&lt;/p&gt;
&lt;p&gt;But you can also store the list of maps in a PV and transform it into CDT later on.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98634?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 13:14:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:48c9a852-7ccf-4395-bd0b-399492f2dd11</guid><dc:creator>johng0005</dc:creator><description>&lt;p&gt;We might end up persisting it in the DB, but for now I was just using the CDT for the key value structure and so the data can be persisted as a process variable.&lt;/p&gt;
&lt;p&gt;I guess if I take your approach I can store it as type &amp;quot;Map&amp;quot; in the process model, right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98633?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 13:07:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:aa1f56d6-9f8f-4528-ba7f-716bf4f99eb5</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Hm ... do you need to persist this data to DB? If not, why even using a CDT&amp;nbsp;where a&amp;nbsp;map would do it?&lt;/p&gt;
&lt;p&gt;You could go with&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;{
  a!map(section: &amp;quot;NAME&amp;quot;, open: true),
  a!map(section: &amp;quot;AGE&amp;quot;, open: false),
  .
  .
  .
  
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;To find the value, use displayvalue like this&lt;/p&gt;
&lt;p&gt;displayvalue(cons!SECTION_NAME, local!status.name, local!status.open, false)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98632?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:57:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5093612b-fb8f-4a22-8b07-aebbcb4fdf10</guid><dc:creator>johng0005</dc:creator><description>&lt;p&gt;How would I keep this persisted in a key-value fashion? That&amp;#39;s why I created the CDT, so I could have it in a key-value fashion and persist the data as a process variable in the relevant process model.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98631?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:54:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:08c0f609-de7c-4373-adfa-a71720713821</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Why not store this in a key-value fashion? Then you can store the section technical names in constants and easily refer to them in UI and in the key-value store.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98630?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:41:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:18e9adbc-641b-47f4-a469-610fad996d8f</guid><dc:creator>johng0005</dc:creator><description>&lt;p&gt;Hey Peter, I&amp;#39;ve replied to Stefan&amp;#39;s comment below.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98629?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:41:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9a832022-dba9-4309-ada3-ed392682a801</guid><dc:creator>johng0005</dc:creator><description>&lt;p&gt;We have a list of attribute sections that a user can click through, and I need to keep track of which sections have been opened for editing. I&amp;#39;ve created a CDT that contains the list of attribute sections as the keys and booleans as the values, but I can&amp;#39;t make the field names match the attribute section names exactly (one of them has a special character) and I can&amp;#39;t make the field names the attribute index because Appian doesn&amp;#39;t allow numerical values as field names.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I was planning to do was to get the attribute section index, and use that to index the CDT to fetch the corresponding value.&lt;/p&gt;
&lt;p&gt;So for example:&lt;/p&gt;
&lt;p&gt;Attribute sections indexes and names that a user sees:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. Name&lt;/p&gt;
&lt;p&gt;2. Age &amp;amp; Address&lt;/p&gt;
&lt;p&gt;3. Occupation&lt;/p&gt;
&lt;p&gt;CDT structure:&lt;/p&gt;
&lt;p&gt;&amp;#39;type!{urn:com:appian:types:TEST}TEST_isSectionOpenForEditing&amp;#39;(&lt;br /&gt;name: 1,&lt;br /&gt;ageAndAddress:&amp;nbsp;0,&lt;/p&gt;
&lt;p&gt;occupation: 1&lt;br /&gt; )&lt;/p&gt;
&lt;p&gt;If the user clicks the second attribute section, Age &amp;amp; Address, I want to fetch the corresponding value from the CDT to verify whether that section is open for editing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Let me know if that makes sense.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98627?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:26:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:21533d09-318f-4445-a18e-ce3aedc4f50f</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Keep in mind that this is dependent on the original structure and ordering of the CDT, not necessarily on what data is provided. So in your example even if &amp;quot;firstName&amp;quot; is the first key you provide in your expression, if the CDT has a different first field (e.g. ID), then it will always return the ID instead.&lt;/p&gt;
&lt;p&gt;Like Stefan mentioned below, I&amp;#39;m curious how you plan to use this - there may be other approaches that could achieve what you&amp;#39;re looking for more consistently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98626?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:24:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bc256fef-2590-48e0-9a74-3ddb019a49af</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Is there a specific reason to do that? While the order is typically fix, I would definitely not rely on it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to fetch a CDT field by numerical index?</title><link>https://community.appian.com/thread/98623?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 11:33:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a5cc5a9a-2729-4d43-9577-2065094e0691</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;Change the value of the local!index variable to your desired index.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: &amp;#39;type!{urn:com:appian:types:DA}DA_Student&amp;#39;(
    firstName_txt: &amp;quot;Harshit&amp;quot;,
    lastName_txt: &amp;quot;Bumb&amp;quot;
  ),
  local!keys: a!keys(local!data),
  local!index: 3,
  local!selectedkey: index(local!keys,local!index,{}),
  index(local!data,local!selectedkey,{})
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>