comparing values of CDT in array

Hello,

 

I have a local variable storing list of CDT as array.

local!b:{
'type!{urn:com:appian:types:folders}CMN_RootCaseFolder'( objectId: "1", objectName: "A", parentId: "1"),
'type!{urn:com:appian:types:folders}CMN_RootCaseFolder'( objectId: "2", objectName: "B",parentId: "2"),
'type!{urn:com:appian:types:folders}CMN_RootCaseFolder'( objectId: "3", objectName: "C", parentId: "2"),
'type!{urn:com:appian:types:folders}CMN_RootCaseFolder'( objectId: "4", objectName: "D", parentId: "1"),
'type!{urn:com:appian:types:folders}CMN_RootCaseFolder'( objectId: "5", objectName: "E", parentId: "1"
'type!{urn:com:appian:types:folders}CMN_RootCaseFolder'( objectId: "6", objectName: "F", parentId: "2")
},

 

In this array of CDT type, the logic which I am trying to achieve is to check if the array element object id is acting as parent of other array elements present in the same local!b.

For Example: the objectId="1" is present as parentId in 2 elements (objectName=D,E)

Please suggest how to achieve it.

Any response would be appreciated.

Thanks in advance,

Divya

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    Hi for this you need to do looping over this cdt array using a!foreach()

    Where during each iteration you need to use wherecontains() to check whether this current cdt object id is present as parentid to some other cdt or not, if yes, store it's index in a local variable using append.

    This should work.

    But out of interest, let's assume you have got the CDT indexes where id is being referred as parentid, then what? What exactly you are trying to achieve, I mean, you just want to know the CDT indexes or you want to do some manipulation on this?
  • +1
    Certified Lead Developer

    Hello Divyaa,

     

    To achieve your requirement (For Example: the objectId="1" is present as parentId in array elements) refer below code,

     

    load(
    local!arrRootCaseFolder:{
    type!CMN_RootCaseFolder(
    objectId: 1,
    objectName: "A",
    parentId: 1
    ),
    type!CMN_RootCaseFolder(
    objectId: 2,
    objectName: "B",
    parentId: 2
    ),
    type!CMN_RootCaseFolder(
    objectId: 3,
    objectName: "C",
    parentId: 2
    ),
    type!CMN_RootCaseFolder(
    objectId: 4,
    objectName: "D",
    parentId: 1
    ),
    type!CMN_RootCaseFolder(
    objectId: 5,
    objectName: "E",
    parentId: 1
    ),
    type!CMN_RootCaseFolder(
    objectId: 6,
    objectName: "F",
    parentId: 2
    )
    },
    local!result: index(local!arrRootCaseFolder,whereContains(1,index(local!arrRootCaseFolder,"parentId",0)),""),
    local!result

    )

    Output:

     

    Type

    CMN_RootCaseFolder?list

     
     
    Value

    [objectId=1, objectName=A, parentId=1]; [objectId=4, objectName=D, parentId=1]; [objectId=5, objectName=E, parentId=1]

     
     
     
  • 0
    A Score Level 1
    in reply to jaidw
    Thank you . I was able to move ahead with your solution. But still curious to know how is this kind of looping carried out. In the above example, the whereContains() has 1 as value to be found, but if I have to check through all the CDT list with the value to found is the objectId value present in CDT in whereContains().
  • 0
    Certified Lead Developer
    in reply to divyaa
    From the above comment, what I understood is, you are looking to make it dynamic(instead of hard code). Simply use a apply() loop for each desired parentId.