CDT with an Integer List

I have a result set from a series of operations that looks like:

myCDT:{

label: "some name",

data: 0,1,12,0,14,234

}

"data" is an integer array - but may have a variable number of Elements.

I've got a List of myCDT's and want to create an array of integers that is the sum of each positional integer column (e.g add up all of data[1], data[2], etc)

Any good ideas on how to do this?

Ultimately  all I need is a total row in some grids, but there doesn't seem to be a way to do that.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    try using the reduce() function
    docs.appian.com/.../fnc_looping_reduce.html

    I think you can create a slice using index like 

    index(index(myCDT_Array,"data",{}),1,{})

    You'll somehow need to manage the positional index as needed. 

  • I tried this too, and received oddly similar results to Poorna's approach.
  • 0
    Certified Associate Developer
    in reply to Richard
    load(
    local!myCDT:{
      {label:"First Row", data:tointeger({1,2,3,4})},
      {label:"Second Row",data:{5,6,7,8}},
      {label:"Third Row",data:{9,0,1,2}}
    },
    {

    a!paragraphField(
      label: "Output", readOnly: true(),
      value: apply(
        fn!sum,
          merge(
            apply(fn!tointeger,local!myCDT[1].data),
            apply(fn!tointeger,local!myCDT[2].data),
            apply(fn!tointeger,local!myCDT[3].data)
          )
        )
      )
    }
    )

    The trick here is using fn!merge to create the myCDT.data[1], myCDT.data[2], myCDT.data[3] arrays before you pass it to fn!sum (note the position of the [1] operator in my example above).  
     
    I had to use fn!tointeger on each of the data elements before the merge command would work because the example arrays at the top are defined as type variant but if you're using a proper CDT this shouldn't be necessary.  To make this work over a dynamic number of data elements you'll have to move the local!myCDT[X].data operator into its own expression that you can use apply on again but aside from that this should work.
     
     
Reply
  • 0
    Certified Associate Developer
    in reply to Richard
    load(
    local!myCDT:{
      {label:"First Row", data:tointeger({1,2,3,4})},
      {label:"Second Row",data:{5,6,7,8}},
      {label:"Third Row",data:{9,0,1,2}}
    },
    {

    a!paragraphField(
      label: "Output", readOnly: true(),
      value: apply(
        fn!sum,
          merge(
            apply(fn!tointeger,local!myCDT[1].data),
            apply(fn!tointeger,local!myCDT[2].data),
            apply(fn!tointeger,local!myCDT[3].data)
          )
        )
      )
    }
    )

    The trick here is using fn!merge to create the myCDT.data[1], myCDT.data[2], myCDT.data[3] arrays before you pass it to fn!sum (note the position of the [1] operator in my example above).  
     
    I had to use fn!tointeger on each of the data elements before the merge command would work because the example arrays at the top are defined as type variant but if you're using a proper CDT this shouldn't be necessary.  To make this work over a dynamic number of data elements you'll have to move the local!myCDT[X].data operator into its own expression that you can use apply on again but aside from that this should work.
     
     
Children