Skip to main content
April 30, 2024
Question

Select multiple users listed from multiple groups and remove them

  • April 30, 2024
  • 6 replies
  • 0 views

Use case is that we have to remove the selected multiple users from multiple groups.

The issue is when I select one user then the entire row is selected of groups listed users.

I want to select the users in multiple from the selected group.

a!localVariables(
  local!selectionValue: {},
  local!selectedGroup: ri!initialGroup,
  local!actionTaken: if(
    isnull(ri!btnAction),
    false,
    or(ri!btnAction = "ADD", ri!btnAction = "MOVE")
  ),
  local!distinctUsers: if(
    a!isNullOrEmpty(local!selectedGroup),
    "Please select a group",
    a!flatten(
      a!forEach(
        items: local!selectedGroup,
        expression: a!localVariables(
          local!group: fv!item,
          a!forEach(
            items: getdistinctusers({ fv!item }),
            expression: a!map(
              id: fv!index,
              Group: local!group,
              Members: fv!item
            )
          )
        )
      )
    )
  ),
  local!pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 10),
  {
    a!cardLayout(
      contents: {
        a!richTextDisplayField(
          labelPosition: "COLLAPSED",
          value: {
            a!richTextItem(
              text: { "USER AND GROUP MANAGEMENT" },
              size: "MEDIUM_PLUS",
              style: { "STRONG" }
            )
          },
          align: "CENTER",
          marginAbove: "STANDARD",
          marginBelow: "STANDARD"
        )
      },
      height: "AUTO",
      style: "STANDARD",
      marginBelow: "STANDARD",
      decorativeBarPosition: "BOTTOM"
    ),
    a!columnsLayout(
      columns: {
        a!columnLayout(
          contents: {}
        ),
        a!columnLayout(
          contents: {
            a!richTextDisplayField(
              labelPosition: "COLLAPSED",
              value: {
                a!richTextItem(
                  text: {
                    "Please select the groups the from here."
                  },
                  color: "ACCENT",
                  size: "MEDIUM_PLUS"
                )
              }
            ),
            a!pickerFieldGroups(
              labelPosition: "ABOVE",
              maxSelections: 5,
              value: ri!initialGroup,
              saveInto: {
                ri!initialGroup,
                a!save(
                  {
                    ri!btnAction,
                    ri!userToRemove,
                    ri!addedtoGroup,
                    ri!removefromGroup,
                    ri!userToAdd,
                    local!selectionValue
                  },
                  null
                )
              }
            ),
            a!richTextDisplayField(
              labelPosition: "COLLAPSED",
              value: {
                a!richTextItem(
                  text: {
                    "Group Members ListÂ%A0"
                  },
                  size: "MEDIUM"
                )
              }
            ),
            a!columnsLayout(
              columns: a!forEach(
                items: local!selectedGroup,
                expression: a!columnLayout(
                  a!gridField(
                    label: "",
                    labelPosition: "ABOVE",
                    data: index(
                      local!distinctUsers,
                      wherecontains(
                        touniformstring(fv!item),
                        touniformstring(local!distinctUsers.Group)
                      )
                    ),
                    columns: {
                      a!gridColumn(
                        label: group(
                          groupId: togroup(fv!item),
                          property: "groupName"
                        ),
                        value: fv!row.Members
                      )
                    },
                    pagingSaveInto: local!pagingInfo,
                    selectable: true,
                    selectionStyle: "ROW_HIGHLIGHT",
                    selectionValue: local!selectionValue,
                    selectionSaveInto: local!selectionValue,
                    selectionRequired: false,
                    maxSelections: null,
                    showSelectionCount: "ON",
                    shadeAlternateRows: true
                  )
                )
              ),
              showDividers: false
            ),
            a!buttonArrayLayout(
              buttons: {
                a!buttonWidget(
                  label: "Remove Member",
                  value: "REMOVE",
                  saveInto: {
                    ri!btnAction,
                    a!save(
                      ri!userToRemove,
                      local!selectionValue
                    ),
                    a!save(
                      ri!removefromGroup,
                      ri!initialGroup
                    )
                  },
                  submit: true,
                  style: "SOLID",
                  color: "#ff0000",
                  disabled: or(
                    local!actionTaken,
                    not(a!isNotNullOrEmpty(local!selectionValue))
                  ),
                  showWhen: a!isNotNullOrEmpty(local!selectionValue),
                  confirmHeader: "Remove Members",
                  confirmMessage: "Are you sure you want to remove the selected members from the group?",
                  confirmButtonLabel: "Yes, Remove Members"
                )
              }
            ),
            a!horizontalLine(
              weight: "THICK",
              color: "#0000ff",
              style: "SOLID",
              marginAbove: "STANDARD",
              marginBelow: "STANDARD"
            ),
            a!linkField(
              labelPosition: "COLLAPSED",
              links: {
                a!dynamicLink(
                  label: "+ Add Users to Selected Group",
                  value: "ADD",
                  saveInto: {
                    ri!btnAction,
                    a!save(ri!addedtoGroup, ri!initialGroup)
                  }
                )
              },
              showWhen: not(local!actionTaken)
            ),
            a!sectionLayout(
              label: "Add Users",
              contents: {
                a!pickerFieldUsers(
                  label: "Users to Add",
                  value: ri!usertoAdd,
                  saveInto: a!save(
                    ri!usertoAdd,
                    if(isnull(save!value), {}, save!value)
                  ),
                  required: true
                )
              },
              showWhen: ri!btnAction = "ADD"
            )
          },
          width: "WIDE_PLUS"
        ),
        a!columnLayout(
          contents: {}
        )
      }
    ),

    a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "ADD USER",
          value: "ADD",
          submit: true,
          style: "SOLID"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: null,
          saveInto: { ri!btnAction, ri!initialGroup },
          style: "OUTLINE",
          showWhen: local!actionTaken
        )
      },
      showWhen: local!actionTaken
    )
  }
)

    6 replies

    stefanhelzle0001
    Brainy
    April 30, 2024

    It seems like all your grids use the same local variable to select users. This would not be an issue if the identifiers of the grid rows would be different. But you are only passing a list into the grid, and then the grid uses the index as the identifier. Now, each grid has a row with identifier 1 (one).

    April 30, 2024

    Understood, Is there any way to solve this issue?

    stefanhelzle0001
    Brainy
    April 30, 2024

    Create a datasubset including proper values for the identifiers field. Then the grid will use that.

    You could also create a separate selection value for each grid, then the interference would go away. Then, you would have to add some logic to join all selections.