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

Parents
  • 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!

Reply
  • 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!

Children
No Data