Duplicated and wrong data saving when using dynamic input

Hello,

I have a problem on my form interface that I can't figure out, I have a dynamic input that can add more paragraph fields if needed but when the form is submitted, two records are created with the same data saved, and only the last text from the different paragraph fields created by the dynamic input is saved in the duplicated records but with 2 differents ID.

I'm new to development and to Appian and I'm not english so I have difficulties to understand what can be the source of the problem, I tried many things using documentation but it's unsuccessfull.

All my form's data is saved in my record type "HELLO Evaluation", except for the text from the different paragraph fields who are saved in my record type "HELLO Objectif" by a one Evaluation to many Objectifs relationship.

Here's my code, I suppose the problem comes from the paragraph field code (259 to 288) or the submit button (348 to 376) but I'll give you all of it in case I'm wrong : 

a!localVariables(
  local!bdd,
  local!unite,
  local!chaqueobjectif,
  local!unitedisponible: choose(
    if(isnull(local!bdd), 1, local!bdd),
    {
      "********",
      "********",
      "********",
      "********",
      "********"
    },
    {
      "********",
      "********",
      "********",
      "********",
      "********"
    },
    {
      "********",
      "********",
      "********",
      "********",
      "********"
    },
    {
      "********",
      "********",
      "********",
      "********",
      "********"
    }
  ),
  local!activeStep: 1,
  local!steps: {
    "Vos biodatas",
    "Votre affectation",
    "Vos objectifs",
    "Résumé"
  },
  a!formLayout(
    label: "Vos données pour l'évaluation",
    contents: {
      a!milestoneField(
        steps: local!steps,
        links: a!forEach(
          items: local!steps,
          expression: if(
            local!activeStep <= fv!index,
            null,
            a!dynamicLink(
              saveInto: a!save(local!activeStep, fv!index)
            )
          )
        ),
        active: local!activeStep
      ),
      a!sectionLayout(
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: a!textField(
                  label: "Grade",
                  placeholder: "Veuillez entrer votre grade actuel",
                  value: if(
                    a!isNullOrEmpty(
                      ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{6d9ce6fd-a150-44da-8dc3-f31f98df34d7}grade']
                    ),
                    user(loggedInUser(), "displayName"),
                    ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{6d9ce6fd-a150-44da-8dc3-f31f98df34d7}grade']
                  ),
                  saveinto: ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{6d9ce6fd-a150-44da-8dc3-f31f98df34d7}grade'],
                  required: true(),
                  requiredMessage: "Merci de renseigner vos biodatas",
                  readOnly: if(
                    local!activeStep = length(local!steps),
                    true(),
                    false()
                  )
                )
              ),
              a!columnLayout(
                contents: a!textField(
                  label: "Nom",
                  placeholder: "veuillez entrer votre nom",
                  value: if(
                    a!isNullOrEmpty(
                      ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{f7671ce8-f437-4d60-a66a-674f06c990f5}nom']
                    ),
                    user(loggedInUser(), "lastName"),
                    ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{f7671ce8-f437-4d60-a66a-674f06c990f5}nom']
                  ),
                  saveinto: ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{f7671ce8-f437-4d60-a66a-674f06c990f5}nom'],
                  required: true(),
                  requiredMessage: "Merci de renseigner vos biodatas",
                  readOnly: if(
                    local!activeStep = length(local!steps),
                    true(),
                    false()
                  )
                )
              ),
              a!columnLayout(
                contents: a!textField(
                  label: "Prénom",
                  placeholder: "veuillez entrer votre prénom",
                  value: if(
                    a!isNullOrEmpty(
                      ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{7f04005d-2795-4d55-90f0-9bd1f9b426c5}prenom']
                    ),
                    user(loggedInUser(), "firstName"),
                    ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{7f04005d-2795-4d55-90f0-9bd1f9b426c5}prenom']
                  ),
                  saveinto: ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{7f04005d-2795-4d55-90f0-9bd1f9b426c5}prenom'],
                  required: true(),
                  requiredMessage: "Merci de renseigner vos biodatas",
                  readOnly: if(
                    local!activeStep = length(local!steps),
                    true(),
                    false()
                  )
                )
              ),
              a!columnLayout(
                contents: a!dropdownField(
                  label: "Millésime",
                  placeholder: "Veuillez choisir un millésime",
                  choiceLabels: {
                    "2022",
                    "2023",
                    "2024",
                    "2025",
                    "2026",
                    "2027",
                    "2028",
                    "2029",
                    "2030"
                  },
                  choiceValues: {
                    2022,
                    2023,
                    2024,
                    2025,
                    2026,
                    2027,
                    2028,
                    2029,
                    2030
                  },
                  value: ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{013891f2-c41d-421e-ab59-a415e97b22d5}millesime'],
                  saveinto: ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{013891f2-c41d-421e-ab59-a415e97b22d5}millesime'],
                  required: true(),
                  requiredMessage: "Merci de choisir le millésime pour cet évaluation",
                  disabled: if(
                    local!activeStep = length(local!steps),
                    true(),
                    false()
                  )
                )
              )
            }
          ),
          a!textField(
            value: "Veuillez vérifier et corriger vos biodatas si nécessaire, puis choisir un millésime.",
            showWhen: not(local!activeStep = length(local!steps)),
            readOnly: true(),
            align: "CENTER"
          )
        },
        showWhen: or(
          local!activeStep = { 1, length(local!steps) }
        )
      ),
      a!sectionLayout(
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: a!dropdownField(
                  label: "Votre BDD",
                  placeholder: "Choisissez votre BDD d'appartenance",
                  choicelabels: {
                    "BDD AMS",
                    "BDD IDF",
                    "BDD BGA",
                    "BDD FAA"
                  },
                  choicevalues: { 1, 2, 3, 4 },
                  value: local!bdd,
                  saveinto: {
                    local!bdd,
                    a!save(local!unite, null),
                    a!save(
                      ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{fb9d0fbf-3643-4322-9179-e465dd64f8b0}bdd'],
                      local!bdd
                    )
                  },
                  required: true(),
                  requiredMessage: "Veuillez choisir votre BDD",
                  disabled: if(
                    local!activeStep = length(local!steps),
                    true(),
                    false()
                  )
                )
              ),
              a!columnLayout(
                contents: a!dropdownField(
                  label: "Unité",
                  placeholder: "Choisissez votre unité",
                  choiceLabels: local!unitedisponible,
                  choiceValues: local!unitedisponible,
                  value: local!unite,
                  saveinto: {
                    local!unite,
                    a!save(
                      ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{6812b5d5-da5e-400b-8b82-d77040621eda}unite'],
                      local!unite
                    )
                  },
                  required: true(),
                  requiredMessage: "Veuillez choisir votre unité",
                  disabled: or(
                    isnull(local!bdd),
                    if(
                      local!activeStep = length(local!steps),
                      true(),
                      false()
                    )
                  )
                )
              )
            }
          )
        },
        showWhen: or(
          local!activeStep = { 2, length(local!steps) }
        )
      ),
      a!sectionLayout(
        contents: {
          {
            a!localVariables(
              local!objectifs: { "" },
              a!sectionLayout(
                contents: {
                  a!richTextDisplayField(
                    labelPosition: "COLLAPSED",
                    value: {
                      a!richTextItem(
                        text: "Objectifs (4 maximum)",
                        style: "STRONG"
                      )
                    }
                  ),
                  a!forEach(
                    items: local!objectifs,
                    expression: {
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!paragraphField(
                              label: "Objectif" & " " & fv!index,
                              labelPosition: "ADJACENT",
                              placeholder: "Veuillez entrer votre objectif",
                              value: fv!item,
                              saveInto: {
                                fv!item,
                                a!save(
                                 local!chaqueobjectif,
                                  fv!item
                                )
                              },
                              refreshAfter: "UNFOCUS",
                              characterLimit: 500,
                              required: true(),
                              requiredMessage: "Veuillez désigner un objectif",
                              readOnly: if(
                                local!activeStep = length(local!steps),
                                true(),
                                false()
                              ),
                              validations: {}
                            )
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              labelPosition: "COLLAPSED",
                              value: {
                                a!richTextIcon(
                                  icon: "times",
                                  altText: "Remove number",
                                  link: a!dynamicLink(
                                    saveInto: a!save(
                                      local!objectifs,
                                      remove(local!objectifs, fv!index)
                                    )
                                  ),
                                  linkStyle: "STANDALONE"
                                )
                              },
                              showWhen: count(local!objectifs) > 1
                            ),
                            width: "MINIMIZE"
                          )
                        },
                        alignVertical: "MIDDLE"
                      )
                    }
                  ),
                  a!richTextDisplayField(
                    labelPosition: "COLLAPSED",
                    value: a!richTextItem(
                      text: {
                        a!richTextIcon(icon: "plus", altText: "plus"),
                        " ",
                        "Ajouter un objectif"
                      },
                      link: a!dynamicLink(
                        saveInto: {
                          a!save(
                            local!objectifs,
                            append(local!objectifs, "")
                          )
                        },
                        
                      ),
                      linkStyle: "STANDALONE",
                      showWhen: and(
                        count(local!objectifs) < 4,
                        not(local!activeStep = length(local!steps))
                      )
                    )
                  )
                }
              )
            )
          }
        },
        showWhen: or(
          local!activeStep = { 3, length(local!steps) }
        )
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Terminé",
          saveInto: {
            a!forEach(
              items: local!chaqueobjectif,
              expression: a!save(
                ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.relationships.{9e81be1f-0840-4b7a-8fb1-5ee893075094}helloObjectif.fields.{c555eaf6-3c4b-4f6c-9373-ecdb02e24cff}textofobjectif'], fv!item
              )
            ),
            a!save(
              ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{e6accd54-1587-4a28-801a-ad47748cfa1f}createdBy'],
              loggedInUser()
            ),
            a!save(
              ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{ee3b80ba-5ee5-41de-a4b1-5410ab4bd26d}statusId'],
              1
            ),
            a!save(
              ri!evaluation['recordType!{6df20a97-ad05-4def-a379-e756e76e388a}HELLO Evaluation.fields.{ffe06b38-e6cc-4291-acf6-4f6c3ab35fa9}createdOn'],
              now()
            )
          },
          submit: true,
          style: "PRIMARY",
          showWhen: local!activeStep = length(local!steps)
        ),
        a!buttonWidget(
          label: "Suivant",
          value: local!activeStep + 1,
          saveInto: { local!activeStep },
          style: "PRIMARY",
          showWhen: local!activeStep <> length(local!steps),
          validate: true
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Retour",
          value: local!activeStep - 1,
          saveInto: local!activeStep,
          showWhen: local!activeStep > 1
        ),
        a!buttonWidget(
          label: "Annuler",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "LINK",
          validate: false
        )
      }
    )
  )
)

(I changed some of the text for security and confidentiality reasons)

I'm new to all this, I hope someone will be able to help me, ask me if you need more infos.

Thanks

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Hi, 

    If my understanding is correct you are expecting "the records on the relational table with its respective values provided by the user instead of the same value provided at last, here local!chaqueobjectif is storing the last paragraph field text alone, try the append function to store the array value as you did for local!objectifs. 

  • 1) I'm unclear what the desired output structure for "ri!evaluation" is, with respect to the paragraph text(s).  Are you trying to create a separate row for each text provided, or trying to stuff them all together into one row?

    2) The way you're saving into "local!chaqueObjectif" here is not doing what I suspect you're wanting it to do.  Every time the user interacts with any of the paragraph fields defined here, local!chaqueObjectif will be overwritten with that singular value.  Later (in your saveInto referenced above), you're trying to loop over it using a!forEach, but as currently configured it would not be possible for it to contain an array of values.  Line 354 should probably just be changed to reference local!objectifs.  And I don't think local!chaqueObjectif actually serves any purpose (though it could be a handy "debugging" tool, since it would always reflect the most recent edited paragraph field value).