Hi all,
I want to get fields in a CDT based on their numerical index, i.e. if I have a CDT like:
{'type!{urn:com:appian:types:TEST}TEST_Employee'('firstName': "Frank", 'secondName': "Smith", 'age': 29)}
To get the first field, is there a way to index it by number? Something like index(local!testCdt, 1, null) would return "Frank".
Thanks for your help!
Discussion posts and replies are publicly visible
Change the value of the local!index variable to your desired index.
a!localVariables( local!data: 'type!{urn:com:appian:types:DA}DA_Student'( firstName_txt: "Harshit", lastName_txt: "Bumb" ), local!keys: a!keys(local!data), local!index: 3, local!selectedkey: index(local!keys,local!index,{}), index(local!data,local!selectedkey,{}) )
Is there a specific reason to do that? While the order is typically fix, I would definitely not rely on it.
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 "firstName" 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.
Like Stefan mentioned below, I'm curious how you plan to use this - there may be other approaches that could achieve what you're looking for more consistently.
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've created a CDT that contains the list of attribute sections as the keys and booleans as the values, but I can't make the field names match the attribute section names exactly (one of them has a special character) and I can't make the field names the attribute index because Appian doesn't allow numerical values as field names.
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.
So for example:
Attribute sections indexes and names that a user sees:
1. Name
2. Age & Address
3. Occupation
CDT structure:
'type!{urn:com:appian:types:TEST}TEST_isSectionOpenForEditing'(name: 1,ageAndAddress: 0,
occupation: 1 )
If the user clicks the second attribute section, Age & Address, I want to fetch the corresponding value from the CDT to verify whether that section is open for editing.
Let me know if that makes sense.
Hey Peter, I've replied to Stefan's comment below.
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.
How would I keep this persisted in a key-value fashion? That'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.
Hm ... do you need to persist this data to DB? If not, why even using a CDT where a map would do it?
You could go with
{ a!map(section: "NAME", open: true), a!map(section: "AGE", open: false), . . . }
To find the value, use displayvalue like this
displayvalue(cons!SECTION_NAME, local!status.name, local!status.open, false)
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.
I guess if I take your approach I can store it as type "Map" in the process model, right?
If you plan to persist this, go with a CDT and add a primary key field.
But you can also store the list of maps in a PV and transform it into CDT later on.