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) }
            )
          }
        )
      )
    )

  • +1
    Certified Lead Developer
    in reply to nitinn0007

    Well, I was really hoping you'd edit your previous comment to put the code into a code box, since having that long comment makes the thread more painful to scroll.  But this is about what I meant.

    Where are you getting this example code from originally?  There seems to be a common pattern around here of people getting this editable grid configuration confused.

    So in your updated code you've added "local!grid" which will initially be an array of one member of the empty CDT.  This is ok.  But then you're not actually utilizing it for some reason.

    • The a!forEach() statement that creates the grid rows should have its "items:" parameter set to "local!grid". 
    • The individual fields in the Grid Row should not refer to "local!newGrid.Name", but rather to fv!item.Name, etc.  That way the fields directly edit the relevant row of the array data itself.
    • The Add Row and Remove Row links shouldn't be even touching "ri!item".
      • Add Row should append a new blank row to the end of local!grid
      • Remove Row should remove the current index position from local!grid
    • The "Submit" button should be saving the value of local!grid (not local!newGrid) into ri!item

    Stylistically, it'd be helpful if your local variable names were more descriptive of their actual function.  Instead of "local!newGrid", i'd personally consider renaming it to "local!blankRow", and maybe also renaming "local!grid" to "local!gridRows" or something like that.  This is just to prevent the designer (you or someone else in the future seeing this form) from getting confused as to the intended use of each local variable.

  • +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)
              }
            )
          }
        )
      )
    )

Reply Children
No Data