Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
5 replies
Subscribers
7 subscribers
Views
2898 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
If I have a CDT is there any way for me to list out each of its fields by name d
robbier
over 8 years ago
If I have a CDT is there any way for me to list out each of its fields by name dynamically? I was playing around with some of the functions but haven't seen anything yet.
OriginalPostID-166634
OriginalPostID-166634
Discussion posts and replies are publicly visible
0
Eduardo Fuentes
Appian Employee
over 8 years ago
Example: For a CDT called CSSEngineer the following expression does the trick returning the name of each field that this CDT has.
=split(stripwith(tostring(type!CCSEngineer()),"[]="),",")
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
robbier
over 8 years ago
Works beautifully! Thanks!
Quick follow-up question: any way to dynamically pass in the CCSEngineer() to the type! statement? For example, if I have a rule input ri!value of Anytype is there a way to structure the above statement you gave to dynamically feed this in something like...
local!typeName:typename(typeof(ri!value))
split(stripwith(tostring(type![local!typeName()] ),"[]="),",")
..I know the above doesn't quite work but I've been playing around with something to attempt this..rather then use a handcoded static set of rules to determine the CDT...
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 8 years ago
=split(stripwith(tostring(ri!myAnyTypeRuleInput),"[]="),",")
and when invoking this simply pass the desired local variable holding the data. Since the rule takes Any Type anything can be passed and if the local variable contains a CDT then the tostring() will take care of this without the need for the type! constructor.
I used the type!() constructor as an example, but any local variable, acp or pv or rule input will work.
Example:
1. My rule is defined as =split(stripwith(tostring(ri!myAnyTypeRuleInput),"[]="),",")
2. I name this rule: myProject_getCDTFields
3. I invoke it as
rule!myProject_getCDTFields(local!myVariableThatHoldsCDTData)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Jin Pheh
Certified Associate Developer
over 8 years ago
I've actually written a rule to do exactly this for debugging and I think it's output is a little easier on the eyes. If you toss the below into an interface rule you can pass it any object or array and it will tell you the number of items, the item type and break out all of the fields and their values in an easy to read format. I find it particularly helpful when debugging issues related to single element arrays vs single objects. Note that it doesn't handle nested CDTs very well.
a!paragraphField(
label: "Details: " & rule!lengthNullSafe(ri!object) & " x " & typename(typeof(ri!object)),
value: joinarray(split(joinarray(split(tostring(ri!object), ","), char(10)), "; "), char(10) & char(10)),
readOnly: true()
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
judyg
over 8 years ago
Show elements vertically. Can be used for a CDT or an array.
=joinarray(split(stripwith(ri!object,"[]="),","), char(10))
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel