Hello everyone,I am trying to use expandcdt() function

Hi,

I am trying to expand my CDT using expandcdt() function. It is given that the expand field parameter accepts input in "???function.expandcdt.param.expandField.description???" format. I am unable to figure out the input.

My CDT structure looks something like below,

   empId: ""

  empDepartment: Department(nested CDT)

       dId:

       dName: ""

   empGender: Gender(nested CDT)

       gId:

       gName: ""

   lastName: ""

   firstName: ""

Could you please help me with an example.

Thanks in advance.

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Lead Developer
    in reply to Pradeep Gudishana

    Here's a cheeky solution for your problem. This code will give you list of column names in your cdt that have changed.

    It does not work for nested cdt's but you can try to improve on this. Hope it helps.

    load(
      local!disectCdt: rule!disectCDT(
                          cdt1: 'type!<cdt>'(a: 1, b: "doc1", c: "desc1"),
                          cdt2: 'type!<cdt>'(a: 1, b: "doc1", c: "")
                       ),
      local!cdtColumns: index(index(local!disectCdt, "cdt1"), "columnArray"),
      local!cdt1Values: index(index(local!disectCdt, "cdt1"), "valueArray"),
      local!cdt2Values: index(index(local!disectCdt, "cdt2"), "valueArray"),
      local!changedColumnIndex: where(
                                    a!forEach(
                                    local!cdt1Values,
                                    fv!item <> local!cdt2Values[fv!index]
                                  )
                                ),
      index(local!cdtColumns, local!changedColumnIndex)
    )

     And this is your supporting rule rule!disectCDT

    if(
      runtimetypeof(ri!cdt1) <> runtimetypeof(ri!cdt2),
      null,
      load(
        local!cdt1ToColVal: split(stripwith(touniformstring(ri!cdt1),"[]"),","),
        local!cdt1Columns: a!forEach(local!cdt1ToColVal, split(fv!item, "=")[1]),
        local!cdt1Values: a!forEach(local!cdt1ToColVal, split(fv!item, "=")[2]),
        
        local!cdt2ToColVal: split(stripwith(touniformstring(ri!cdt2),"[]"),","),
        local!cdt2Columns: a!forEach(local!cdt2ToColVal, split(fv!item, "=")[1]),
        local!cdt2Values: a!forEach(local!cdt2ToColVal, split(fv!item, "=")[2]),
        {
          cdt1: {
            columnArray: local!cdt1Columns,
            valueArray: local!cdt1Values
          },
          cdt2: {
            columnArray: local!cdt2Columns,
            valueArray: local!cdt2Values
          }
        }
      )
    )

Children
No Data