If I have a CDT is there any way for me to list out each of its fields by name d

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

  • 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()),"[]="),",")
  • 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...
  • =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)
  • 0
    Certified Associate Developer
    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()
    )
  • Show elements vertically. Can be used for a CDT or an array.
    =joinarray(split(stripwith(ri!object,"[]="),","), char(10))