Getting an error

Hello community,

     I am trying to save my local variable's data into the rule input.

I use editable grid and use of CDT as a local variable. Also, I have taken CDT as a rule input in the array form.

Now when I am trying to save these into rule input than after click on dynamic link, It is overriding the data and show the first time data I have and save  data only one time in the rule input.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    There are two common design concepts for an editable grid like this:

    1. store an array of CDT in a Rule Input; iterate the editable grid rows over that array and store values directly into the individual array members
    2. SEPARATELY, store an array of CDT/Dictionary in a Local variable and iterate the editable grid rows over that, save into that, then when everything is done, save the whole local variable back into the rule input upon Submit Click.

    So you have things kinda jumbled up here, as if you're trying to pick and choose between implementation patterns #1 and #2 above.  I'm not even really sure where to start... I'll try to cover the big-picture issues that i think are preventing the form from working for you in either design concept.

    First: local!newGrid is defined as a single element of your CDT.
    Then: your editable grid rows iterate over the rule input version of the variable, BUT the saveIntos are all pointing at the local variable.

    Your Add Row Link appends the local variable (containing its current value) onto the rule input.  Why?
    And finally, your saveInto overwrites your whole rule input variable with the current value of local!newGrid.  But you've already configured things such that local!newGrid will not represent the array of entries you're trying to create on the form.

    My suggestion: pick one approach instead of this awkward hybrid.  If you're going to assemble your rows of data in a local variable first that's fine, but in this case, usually you should not even *touch* the Rule Input variable until the Submit Click.  local!newGrid should be established at first as an empty array, the grid rows should refer to it, and the add row link should add new blank rows to it.

  • a!localVariables(
    local!newgrid: 'type!{urn:com:appian:types:EC}EC_Data'(),
    local!grid: { local!newgrid },
    a!formLayout(
    label: "Practice",
    contents: {
    a!sectionLayout(
    label: "Nitin",
    contents: {
    a!gridLayout(
    label: "Form",
    labelPosition: "ABOVE",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Name"),
    a!gridLayoutHeaderCell(label: "Department"),
    a!gridLayoutHeaderCell(label: "Document"),
    a!gridLayoutHeaderCell(label: "")
    },
    columnConfigs: {
    a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
    a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
    a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
    a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2)
    },
    rows: {
    {
    a!forEach(
    items: local!newgrid,
    expression: a!gridRowLayout(
    contents: {
    a!textField(
    label: "Name",
    labelPosition: "ABOVE",
    value: local!newgrid.Name,
    saveInto: local!newgrid.Name,
    refreshAfter: "UNFOCUS",
    required: true,
    validations: {}
    ),
    a!multipleDropdownField(
    label: "Department",
    labelPosition: "ABOVE",
    placeholder: "--- Select a Value ---",
    choiceLabels: cons!EC_DEPARTMENT,
    choiceValues: cons!EC_DEPARTMENT,
    value: local!newgrid.Department,
    saveInto: local!newgrid.Department,
    searchDisplay: "AUTO",
    required: true,
    validations: {}
    ),
    a!fileUploadField(
    label: "Document",
    labelPosition: "ABOVE",
    target: cons!EC_PHOTOS,
    value: local!newgrid.Document,
    saveInto: local!newgrid.Document
    ),
    a!richTextDisplayField(
    labelPosition: "COLLAPSED",
    value: {
    a!richTextIcon(
    icon: "window-close",
    altText: "Delete Row Button",
    link: a!dynamicLink(
    label: "Dynamic Link",
    saveInto: {
    a!save(ri!item, remove(ri!item, fv!index))
    }
    ),
    color: "#ff0000"
    )
    }
    )
    }
    )
    )
    }
    },
    selectionSaveInto: {},
    addRowLink: a!dynamicLink(
    label: "Add New Recod",
    saveInto: {
    a!save(ri!item, append(ri!item, local!newgrid))
    }
    ),
    validations: {},
    shadeAlternateRows: true
    )
    }
    )
    },
    buttons: a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Submit",
    icon: "check-circle",
    value: local!newgrid,
    saveInto: { a!save(ri!item, local!newgrid) }
    )
    }
    )
    )
    )

  • 0
    Certified Lead Developer
    in reply to nitinn0007

    If you could edit your comment and post all that code in a Code Box (making sure to re-copy it to retain indentation, etc), that would help a lot.

  • a!localVariables(
      local!newgrid: 'type!{urn:com:appian:types:EC}EC_Data'(),
      local!grid: { local!newgrid },
      a!formLayout(
        label: "Practice",
        contents: {
          a!sectionLayout(
            label: "Nitin",
            contents: {
              a!gridLayout(
                label: "Form",
                labelPosition: "ABOVE",
                headerCells: {
                  a!gridLayoutHeaderCell(label: "Name"),
                  a!gridLayoutHeaderCell(label: "Department"),
                  a!gridLayoutHeaderCell(label: "Document"),
                  a!gridLayoutHeaderCell(label: "")
                },
                columnConfigs: {
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2)
                },
                rows: {
                  {
                    a!forEach(
                      items: local!newgrid,
                      expression: a!gridRowLayout(
                        contents: {
                          a!textField(
                            label: "Name",
                            labelPosition: "ABOVE",
                            value: local!newgrid.Name,
                            saveInto: local!newgrid.Name,
                            refreshAfter: "UNFOCUS",
                            required: true,
                            validations: {}
                          ),
                          a!multipleDropdownField(
                            label: "Department",
                            labelPosition: "ABOVE",
                            placeholder: "--- Select a Value ---",
                            choiceLabels: cons!EC_DEPARTMENT,
                            choiceValues: cons!EC_DEPARTMENT,
                            value: local!newgrid.Department,
                            saveInto: local!newgrid.Department,
                            searchDisplay: "AUTO",
                            required: true,
                            validations: {}
                          ),
                          a!fileUploadField(
                            label: "Document",
                            labelPosition: "ABOVE",
                            target: cons!EC_PHOTOS,
                            value: local!newgrid.Document,
                            saveInto: local!newgrid.Document
                          ),
                          a!richTextDisplayField(
                            labelPosition: "COLLAPSED",
                            value: {
                              a!richTextIcon(
                                icon: "window-close",
                                altText: "Delete Row Button",
                                link: a!dynamicLink(
                                  label: "Dynamic Link",
                                  saveInto: {
                                    a!save(ri!item, remove(ri!item, fv!index))
                                  }
                                ),
                                color: "#ff0000"
                              )
                            }
                          )
                        }
                      )
                    )
                  }
                },
                selectionSaveInto: {},
                addRowLink: a!dynamicLink(
                  label: "Add New Recod",
                  saveInto: {
                    a!save(ri!item, append(ri!item, local!newgrid))
                  }
                ),
                validations: {},
                shadeAlternateRows: true
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              icon: "check-circle",
              value: local!newgrid,
              saveInto: { a!save(ri!item, local!newgrid) }
            )
          }
        )
      )
    )

Reply Children
  • +1
    Certified Lead Developer
    in reply to nitinn0007

    I edited your code into something workable, fwiw:

    a!localVariables(
      local!emptyRow: /*'type!{urn:com:appian:types:EC}EC_Data'(),*/
      a!map(
        Name: null(),
        Department: {}
      ),
      local!gridRows: { local!emptyRow },
      
      a!formLayout(
        label: "Practice",
        contents: {
          a!sectionLayout(
            label: "Nitin",
            contents: {
              a!gridLayout(
                label: "Form",
                labelPosition: "ABOVE",
                headerCells: {
                  a!gridLayoutHeaderCell(label: "Name"),
                  a!gridLayoutHeaderCell(label: "Department"),
                  a!gridLayoutHeaderCell(label: "Document"),
                  a!gridLayoutHeaderCell(label: "")
                },
                columnConfigs: {
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                  a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
                  a!gridLayoutColumnConfig(width: "ICON")
                },
                rows: a!forEach(
                  items: local!gridRows,
                  expression: a!gridRowLayout(
                    contents: {
                      a!textField(
                        label: "Name",
                        labelPosition: "ABOVE",
                        value: fv!item.Name,
                        saveInto: fv!item.Name,
                        refreshAfter: "UNFOCUS",
                        required: true,
                        validations: {}
                      ),
                      a!multipleDropdownField(
                        label: "Department",
                        labelPosition: "ABOVE",
                        placeholder: "--- Select a Value ---",
                        choiceLabels: {"one", "two"},
                        choiceValues: {"one", "two"},
                        value: fv!item.Department,
                        saveInto: fv!item.Department,
                        searchDisplay: "AUTO",
                        required: true,
                        validations: {}
                      ),
                      a!fileUploadField(
                        label: "Document",
                        labelPosition: "ABOVE",
                        /*target: cons!EC_PHOTOS,*/
                        value: fv!item.Document,
                        saveInto: fv!item.Document
                      ),
                      a!richTextDisplayField(
                        labelPosition: "COLLAPSED",
                        align: "CENTER",
                        value: {
                          a!richTextIcon(
                            icon: "window-close",
                            altText: "Delete Row Button",
                            link: a!dynamicLink(
                              label: "Dynamic Link",
                              saveInto: {
                                a!save(local!gridrows, remove(local!gridrows, fv!index))
                              }
                            ),
                            linkStyle: "STANDALONE",
                            color: "#ff0000"
                          )
                        }
                      )
                    }
                  )
                ),
                /*selectionSaveInto: {},*/
                addRowLink: a!dynamicLink(
                  label: "Add New Record",
                  saveInto: {
                    a!save(
                      local!gridrows,
                      append(local!gridrows, local!emptyRow)
                    )
                  }
                ),
                validations: {},
                shadeAlternateRows: true
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              value: "submit",
              icon: "check-circle",
              submit: true(),
              saveInto: {
                ri!buttonClicked,
                a!save(ri!item, local!gridRows)
              }
            )
          }
        )
      )
    )