correct syntax saving to a multivalue CDT

I know this is due to not enough coffee, but here goes.

I've a simple interface A. I have a CDT defined as an Array type. At runtime, the CDT is populated with data. (cdt[1]).

On click of a button, i wish to save a new set of values to cdt[2] or 3 or whatever.

 

I tried using

saveInto{ target cdt, value@ append(cdt, cdt.field1) but no luck.

What am I missing chaps ?

 

 

  Discussion posts and replies are publicly visible

  • First, create a cdt with the required fields. Second create a rule to map the array values to the cdt using type! constructor. Third call the rule on button click by passing the generated array cdt values. In case of multiple cdts use for each.
  • 0
    Certified Lead Developer
    If you are still looking for a solution.
    I had similar issue the way i used to overcome is as follows. May not be recommended when data set is really huge.
    a!foreach(
    items: ri!cdt.field,
    expression:
    a!save(ri!cdt[fv!index].field,
    {index(ri!multipleListVariable,fv!index,0)}
    )
    )
    PS: the target CDT and multipleListVariable should of same length. Most probably this should be the case.
  • 0
    Certified Lead Developer

    Hey Paul,

    If I'm understanding you correctly, you have a rule input that is a CDT array. It begins with one CDT. You want to append a new CDT to this rule input. 

    mohamedt808 and sagarl511 both had good solutions - I've compiled them into the below code sample to make it clearer what they were suggesting: 

     

    The first button uses dictionary format to add to our CDT array.

    The second button uses casting to add to our CDT array. 

     

    There is one rule input (ri!cdtArray) of Any Type. 

    I also created a CDT named "emp" with two fields, id (number), and name (text). 

    {
      a!forEach(
        items: ri!cdtArray,
        expression: a!textField(
          label: "Item #" & fv!index & ": ",
          value: fv!item,
          readOnly: true
        )
      ),
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label: "Add to RI With Dictionary (1, Brian)",
            saveInto: {
              a!save(
                ri!cdtArray,
                append(
                  ri!cdtArray,
                  {id: 1, name: "brian"}
                )
              )
            }
          ),
          a!buttonWidget(
            label: "Add to RI With Cast (2, Jenny)",
            saveInto: {
              a!save(
                ri!cdtArray,
                append(
                  ri!cdtArray,
                  'type!{urn:com:appian:types}emp'(
                    id: 2,
                    name: "Jenny"
                  )
                )
              )
            }
          )
        }
      )
    }

     

    Hope that helps!

  • 0
    Certified Lead Developer
    Essentially create a new singular value of the CDT type using type constructor and input new values in type constructor, then use either append() function or updateArray() function to stick it onto the end of the array of CDT or update one of the existing values, respectively.

    I think other answers have spelled out in detail how to use type constructor. For a simple enough CDT, I suppose dot notation could work, but it can grow impressively complicated rather swiftly. Type constructor method remains about equally convoluted regardless of size.