Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
+1
person also asked this
people also asked this
Replies
13 replies
Answers
1 answer
Subscribers
7 subscribers
Views
10867 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
get List of Item from CDT
joanneh
over 7 years ago
Hello!
please may I know if there is anyway to get the list of items in a CDT?
For example, if there are 3 items namely the "id", "customerId" and "contacts" within the CDT, how could I get a list of Text containing the name of the items above (i.e. something like an array:{"id","customerId", "contacts"})?
Shall I do a queryrule or something?
Thanks for your time
OriginalPostID-238884
Discussion posts and replies are publicly visible
0
chetany
A Score Level 1
over 7 years ago
Do you want only the attributes of the CDT Type? If you want the attribute fields as well as the values, I would suggest another approach - use the a!toJson function.
Eg: If local!cdt is a CDT with data like this: {id: 1, customerId:23, contacts: {"contact1", "contact2"}} etc, you can just use a!toJson(local!cdt).
If you just want the attributes of a CDT - there is another solution:
Assume that the type of your CDT is Customer. Then you can find the attributes in the Customer CDT as follows:
fn!split(fn!stripwith(fn!tostring(type!Customer()) , "=[] "),",")
It will return all the fields in the CDT as an array
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
vijayy700
over 7 years ago
Yes you will have to create a a!queryEntity() if you want only specific columns in your result and you can make it paraterized.
please refer below link for detailed comparision between Query Rules, a!queryEntity() and queryrecord().
forum.appian.com/.../Querying_Data_From_an_RDBMS.html
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 7 years ago
@vijayy700, the user who posted the question wants only the information about the fields in the CDT, not the actual data from DB(or the data related to those fields in the DB). The attached screenshot by the user clarifies that.
So, queryEntity()/queryRecord() is not needed since it does not solve the problem that the user has
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 7 years ago
@joanneh, for your CDT in the screenshot, the expression will change to:
fn!split(fn!stripwith(fn!tostring(type!OPS_JobOrder()) , "=[] "),",")
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
+1
Stefan Helzle
A Score Level 3
over 7 years ago
Probably another solution which does not rely on splitting is:
apply(xpathsnippet(_, "name(*)"), xpathsnippet(toxml(type!YOU_DATA_TYPE()), "/*/*"))
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
0
Josh
Certified Lead Developer
over 7 years ago
@stefanh791 Never thought to use xpathsnippet()/toxml() to accomplish that. Very slick!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 7 years ago
Yes, I also never thought about xpathsnippet() and toxml() to accomplish this. Cool!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
You are welcome :-)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
joanneh
over 7 years ago
Your ideas are brilliant! I use @chetany's way at first but never realise @stefanh791's way works too!
By the way, may I have a follow up question on @stefanh791's solution?
In the line <type!YOU_DATA_TYPE())>, the scipt in my application looks like the following:
'type!{
abc.def-ghij.com}MY_DATA_TYPE'()
Is there any way that I could making the item MY_DATA_TYPE variable like? so I could replace it with different input?
I have thought of using something like:
concat("'type!{
http://abc.def-ghij.com}"
& ri!dataType & "'()")
But it doesn't work....
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Josh
Certified Lead Developer
over 7 years ago
@joanneh If you are trying to pass in a string "cdtName" it probably won't work. If you are passing in type!myCDT into ri!dataType you could do toxml(cast(typeof(ri!dataType), {}))
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
>