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

  • Hi Ramp,

    Error is because you are using ri!users in your picker field and while appending save!value refers to ri!users which is of type Dictionary and trying to save in User or Group type variable.

    You should be using fv!item in your code for picker field

    a!pickerFieldUsersAndGroups(
    required: true,
    value: fv!item,
    saveInto: fv!item
    ),

    Please give it a try.

    Thanks
    Nafis Khan
  • 0
    Certified Senior Developer
    in reply to nafisk0001
    Thanks for the reply. I tried the way you told but still getting the same error. its throwing the casting error when I clicked the Add item link to add a new row.
  • +1
    Certified Lead Developer

    Hi Ram,

    In the Add Row Link code, instead of appending the save!value append the null value. As shown below.

    addRowlink: a!dynamicLink(
          label: "Add an Item",
          value: {
            Membership: ""
          },
          saveInto: {
            a!save(
              ri!users,
              append(
                ri!users,
                ""
              )
            )
          }
        )

  • 0
    Certified Lead Developer

    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[fv!index],
                          saveInto: ri!users[fv!index]
                        ),
                        /* 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:"",
                    saveInto: {
                      a!save(
                        ri!users,
                        append(
                          ri!users,
                          save!value
                        )
                      )
                    }
                  )
                )
              }
            )
      

    Use this code. If you do not understand what changes I have made, Kindly get back to me.

  • Hi Ram,

    You can use the suggestion provided by Santosh or Aditya.

    What they have actually done is instead of using save!value in addRowLink, they are saving "" or null for next new row.

    It should be working fine.
  • 0
    Certified Senior Developer
    Hi,
    Combination of Santosh and Aditya suggestions working as expected. Thanks a lot for prompt response.
    Corrected Code is:
    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[fv!index],
    saveInto: ri!users[fv!index]
    ),
    /* 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,
    ""
    )
    )
    }
    )
    )
    }
    )
  • 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
                )
              }
            )
          )
        }
      )
    )

  • 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.

  • Hi Aditya, I am using record now. How can I select multiple users at a time in editable grid.