Hi.
I am attempting to make a reusable grid using a passed ri! of type Any with a cdt type being passed into it.
Optionally I am thinking about passing in a list of column names so I can specify the order the grid displays columns in.
From there I wanted to do a foreach generating the N grid columns using field names and types grabbed from the passed cdt..
1.I don't know if there is a way to get a list of all the fields a cdt type has.
2. I am unsure if there is a way to get their types.
Any tips?
Discussion posts and replies are publicly visible
roberts0186 said:I don't know if there is a way to get a list of all the fields a cdt type has.
a!keys() -->
Do you happen to know how to use this with a datasubset?
I had thought i could just use the .data field, but apparently despite grabbing an individual dictionary(which documentation says works) from it, key function doesn't seem to work on it.
roberts0186 said:map function doesn't seem to work
What do you mean by "map function"? Do you mean a!keys()? Or are you trying to do something else? Can you post a code snippet, and share what you were hoping for (versus what you're achieving)?
Sorry. yes the a!keys function on a datasubset.
Example is a!keys(value:ri!mydatasubset.data[1])
value being of the format
[isActive:true,modifiedBy:fin.financeadmin,createdOn:6/21/2021 3:19 PM GMT-05:00,createdBy:finley.financeadmin,purchaseOrderCategory:Haste,clientPoId:To,purchaseOrderId:105]
Returns error for the above line as "The passed parameter(s) are of the wrong type. Received the type Any Type"
I think my original suggestion was that you could add a type (or just type id) as a parameter of your reusable component, and call a!keys() on that type reference inside the component.
For example if you pass a relevant type number (integer), into this code, you get the requested keys: a!keys(cast(6590, {}))
(6590 is an arbitrary CDT type number in my system, sub out for one of yours, which you can discover with the "typeof" function)
The keys function should work on a dictionary. Is it possible that the data you provided is empty? The biggest issue I see with this paradigm is that it is entirely dependent on the data that is provided, so if for any reason there is no data, it won't be possible to generate any columns either.
Peter Lewis said:The keys function should work on a dictionary.
I was able to reproduce Robert's issue actually. If I take a query entity which I already know to return a single known row, and wrap it in a!keys(), i get the pink error "The passed parameter(s) are of the wrong type. Received the type Any Type." I.e. from this:
a!keys(rule!APP_QRY_Person(personId: 87).data[1])
whereas, if i do the exact same query and same row, but cast the result as its type (or just as a!map), it works.
a!keys( cast( typeof( 'type!{urn:com:appian:types:APP}APP_Person'() ), rule!APP_QRY_Person(personId: 87).data[1] ) )
a!keys( cast( typeof( a!map() ), rule!APP_QRY_Person(personId: 87).data[1] ) )
Ah interesting, I guess the result of a query isn't truly a dictionary - it's actually just a list of variant. In that case I agree with your suggestion - probably casting to the map is safest.