Save duplicate value with submit button

Hi,

i have a list of items I want to save to the data.

The output should be ID=4, ID=5, ID=6

However, when submitted,  it duplicates first ID:  ID=4, ID=4, ID=4.

please help.

thanks

a!localVariables(
  local!list: { 4, 5, 6 },
  a!formLayout(
    label: "Form",
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          saveInto: {
            a!save(

              target:ri!Data.ID,

              value:a!forEach(items: local!list, expression: fv!item)
            )
          },
          submit: true,
          style: "PRIMARY"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  )
)

  Discussion posts and replies are publicly visible

  • +1
    Certified Lead Developer

    Is "ri!Data" an Array?  Because you're basically telling your Submit button to write into a (generic, non-array-indexed) ID field of ri!Data, each of the values in local!list in succession.  This will have unpredictable results as-written, even if you pre-populate the array with 3 empty elements.  And if it's not meant to be an array then I'm just lost.

    Going out on a limb a bit (since you didn't really make this clear), I'm guessing what you might really want to end up with is a list of ri!Data elements where the ".ID" properties of that list end up looking like the local!list items (and would cleanly follow the number of items in local!list).  My recommended approach for that is always what I usually describe as "assembling your array first, then saving it into its desired location".

    a!localVariables(
      local!list: { 4, 5, 6 },
      
      a!formLayout(
        label: "Form",
        
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              saveInto: {
                a!save(
                  target: ri!Data,
                  value: a!forEach(
                    items: local!list,
                    
                    /* this should create a new list of dictionaries containing the above values, then (over)write them into ri!Data. */
                    expression: {
                      ID: fv!item
                    }
                  )
                )
              },
              submit: true,
              style: "PRIMARY"
            )
          }
        )
      )
    )

  • 0
    Certified Lead Developer
    in reply to kend0001

    Great, thanks for confirming :)