Editable grid having user or group picker with add and remove row features.

Certified Senior Developer

Hi,

We have requirement of creation of GridLayout(editable) grid with one user or group column having add and remove row features. here is the sample code for the same. but we are facing when clicking the "Add item" link like "Expression evaluation error at function 'append' [line 94]: Could not cast from Dictionary to User or Group. Details: CastInvalid".

 

here ri!users is array of User or Group type. Please do the needful to rectify the casting error.

a!sectionLayout(
          label: "Security Group",
          contents: {
            a!gridLayout(
              label: "Members of New Group:",
              totalCount: count(
                ri!users
              ),
              headerCells: {
                a!gridLayoutHeaderCell(
                  label: "Membership"
                ),
                /* For the "Remove" column */
                a!gridLayoutHeaderCell(
                  label: ""
                )
              },
              rows: a!forEach(
                items: ri!users,
                expression: a!gridRowLayout(
                  contents: {
                    a!pickerFieldUsersAndGroups(
                      required: true,
                      value: ri!users,
                      saveInto: ri!users
                    ),
                    /* For the Removal Column*/
                    a!imageField(
                      label: "delete " & fv!index,
                      images: a!documentImage(
                        document: a!iconIndicator(
                          "REMOVE"
                        ),
                        altText: "Remove User or Group",
                        caption: "Remove ",
                        link: a!dynamicLink(
                          value: fv!index,
                          saveInto: {
                            a!save(
                              ri!users,
                              remove(
                                ri!users,
                                save!value
                              )
                            )
                          }
                        )
                      ),
                      size: "ICON"
                    )
                  },
                  id: fv!index
                )
              ),
              addRowlink: a!dynamicLink(
                label: "Add an Item",
                value: {
                  Membership:""
                },
                saveInto: {
                  a!save(
                    ri!users,
                    append(
                      ri!users,
                      save!value
                    )
                  )
                }
              )
            )
          }
        )

Thanks in advance.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Can you try the below code?

     

    load(
      local!noOfRows: 0,
      a!sectionLayout(
        label: "Security Group",
        contents: {
          a!gridLayout(
            label: "Members of New Group:",
            totalCount: local!noOfRows,
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Membership"
              ),
              /* For the "Remove" column */
              a!gridLayoutHeaderCell(
                label: ""
              )
            },
            rows: a!forEach(
              items: if(
                local!noOfRows < 1,
                null,
                enumerate(
                  local!noOfRows
                ) + 1
              ),
              expression: a!gridRowLayout(
                contents: {
                  a!pickerFieldUsersAndGroups(
                    required: true,
                    value: index(
                      ri!users,
                      fv!index,
                      null
                    ),
                    saveInto: a!save(
                      ri!users[fv!index],
                      if(
                        a!isnullorempty(
                          save!value
                        ),
                        null,
                        save!value
                      )
                    )
                  ),
                  /* For the Removal Column*/
                  a!imageField(
                    label: "delete " & fv!index,
                    images: a!documentImage(
                      document: a!iconIndicator(
                        "REMOVE"
                      ),
                      altText: "Remove User or Group",
                      caption: "Remove ",
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(
                            ri!users,
                            remove(
                              ri!users,
                              save!value
                            )
                          ),
                          a!save(
                            local!noOfRows,
                            local!noOfRows - 1
                          )
                        }
                      )
                    ),
                    size: "ICON"
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add an Item",
              value: null,
              saveInto: {
                a!save(
                  local!noOfRows,
                  local!noOfRows + 1
                )
              }
            )
          )
        }
      )
    )

Reply
  • 0
    Certified Lead Developer

    Can you try the below code?

     

    load(
      local!noOfRows: 0,
      a!sectionLayout(
        label: "Security Group",
        contents: {
          a!gridLayout(
            label: "Members of New Group:",
            totalCount: local!noOfRows,
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Membership"
              ),
              /* For the "Remove" column */
              a!gridLayoutHeaderCell(
                label: ""
              )
            },
            rows: a!forEach(
              items: if(
                local!noOfRows < 1,
                null,
                enumerate(
                  local!noOfRows
                ) + 1
              ),
              expression: a!gridRowLayout(
                contents: {
                  a!pickerFieldUsersAndGroups(
                    required: true,
                    value: index(
                      ri!users,
                      fv!index,
                      null
                    ),
                    saveInto: a!save(
                      ri!users[fv!index],
                      if(
                        a!isnullorempty(
                          save!value
                        ),
                        null,
                        save!value
                      )
                    )
                  ),
                  /* For the Removal Column*/
                  a!imageField(
                    label: "delete " & fv!index,
                    images: a!documentImage(
                      document: a!iconIndicator(
                        "REMOVE"
                      ),
                      altText: "Remove User or Group",
                      caption: "Remove ",
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(
                            ri!users,
                            remove(
                              ri!users,
                              save!value
                            )
                          ),
                          a!save(
                            local!noOfRows,
                            local!noOfRows - 1
                          )
                        }
                      )
                    ),
                    size: "ICON"
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add an Item",
              value: null,
              saveInto: {
                a!save(
                  local!noOfRows,
                  local!noOfRows + 1
                )
              }
            )
          )
        }
      )
    )

Children
  • 0
    Certified Senior Developer
    in reply to vimalkumars
    Thanks vimal... Working as expected. it resolved the Casting issue when the user removed the selected user or group name from the column(not the entire row with the remove link)
  • 0
    Certified Lead Developer
    in reply to ramp

    ramp,

    Below code should work for both the scenarios

    a!sectionLayout(
      label: "Security Group",
      contents: {
        a!gridLayout(
          label: "Members of New Group:",
          totalCount: count(
            ri!users
          ),
          headerCells: {
            a!gridLayoutHeaderCell(
              label: "Membership"
            ),
            /* For the "Remove" column */
            a!gridLayoutHeaderCell(
              label: ""
            )
          },
          rows: a!forEach(
            items: ri!users,
            expression: a!gridRowLayout(
              contents: {
                a!pickerFieldUsersAndGroups(
                  required: true,
                  value: fv!item,
                  maxSelections:1,
                  saveInto: a!save(
                    fv!item,
                    if(
                      a!isnullorempty(
                        save!value
                      ),
                      null,
                      save!value
                    )
                  )
                ),
                /* For the Removal Column*/
                a!imageField(
                  label: "delete " & fv!index,
                  images: a!documentImage(
                    document: a!iconIndicator(
                      "REMOVE"
                    ),
                    altText: "Remove User or Group",
                    caption: "Remove ",
                    link: a!dynamicLink(
                      value: fv!index,
                      saveInto: {
                        a!save(
                          ri!users,
                          remove(
                            ri!users,
                            save!value
                          )
                        )
                      }
                    )
                  ),
                  size: "ICON"
                )
              },
              id: fv!index
            )
          ),
          addRowlink: a!dynamicLink(
            label: "Add an Item",
            value: null,
            saveInto: {
              a!save(
                ri!users,
                append(
                  ri!users,
                  ""
                )
              )
            }
          )
        )
      }
    )

     

    Also, if you just want to pick the multiple user or group, you can directly use the pickerFieldUsersAndGroups component to select multiple values.