How to remove member from particular group, from the grid column using dynamicLink ?

a!localVariables(
  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!sectionLayout(
      label: "User & Group Management",
      contents: {
        a!pickerFieldGroups(
          label: "Pick Groups",
          labelPosition: "ABOVE",
          maxSelections: 5,
          value: ri!initialGroup,
          saveInto: {
            ri!initialGroup,
            a!save(
              {
                ri!btnAction,
                ri!userToRemove,
                ri!userToRemove,
                ri!userToAdd,  
                local!selectedGroup
              },
              null
            )
          },
        )
      }
    ),
    a!sectionLayout(
      label: "Group members",
      contents: {
        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
                  ),
                  a!gridColumn(
                    value: a!richTextDisplayField(
                      value: a!richTextIcon(
                        icon: "times",
                        caption: "Remove User",
                        color: "NEGATIVE",
                        size: "MEDIUM",
                        link: a!dynamicLink(
                          value: fv!row.Members,
                          saveInto: ri!userToRemove
                        )
                      )
                    ),
                    width: "ICON"
                  )
                },
                pagingSaveInto: local!pagingInfo
              )
            )
          ),
          showDividers: true
        ),
        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"
    ),
    a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: if(
            ri!btnAction = "ADD",
            "Add Users",
            "Move User"
          ),
          submit: true,
          style: "SOLID"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: null,
          saveInto: { ri!btnAction, ri!initialGroup,  },
          style: "OUTLINE",
          showWhen: local!actionTaken
        )
      },
      showWhen: local!actionTaken
    )
  }
)

I'd like to remove a specific member from the chosen group using the dynamicLink and add a member to all selected groups.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    hi  

    You can use below code for removing group member from selected group, You can enhance the code if required for your requirement. you can use a!removeGroupMembers() for adding members you can use a!addMembersToGroup() go by process model as   said, this would have save the history for how has ran the process.

    a!gridField(
                    label: "",
                    labelPosition: "ABOVE",
                    data: index(
                      local!distinctUsers,
                      wherecontains(
                        touniformstring(fv!item),
                        touniformstring(local!distinctUsers.Group)
                      )
                    ),
                    selectable: true,
                    selectionValue: local!selection,
                    selectionSaveInto: {
                     
                      local!selection,
                   
                      a!save(local!selectedRows, append(local!selectedRows, fv!selectedRows)),
                     
                      a!save(local!selectedRows, difference(local!selectedRows, fv!deselectedRows))
                    },
                    columns: {
                      a!gridColumn(
                        label: group(
                          groupId: togroup(fv!item),
                          property: "groupName"
                        ),
                        value: fv!row.Members
                      ),
                      a!gridColumn(
                        value: a!richTextDisplayField(
                          value: a!richTextIcon(
                            icon: "times",
                            caption: "Remove User",
                            color: "NEGATIVE",
                            size: "MEDIUM",
                            link: a!dynamicLink(
                              value: fv!row.Members,
                              saveInto: {ri!userToRemove,
                              a!removeGroupMembers(
                                group: local!selectedRows.Group,
                                members: local!selectedRows.Members
                              )
                            }
                            )
                          )
                        ),
                        width: "ICON"
                      )
                    },
                    pagingSaveInto: local!pagingInfo
                  )

Reply
  • 0
    Certified Senior Developer

    hi  

    You can use below code for removing group member from selected group, You can enhance the code if required for your requirement. you can use a!removeGroupMembers() for adding members you can use a!addMembersToGroup() go by process model as   said, this would have save the history for how has ran the process.

    a!gridField(
                    label: "",
                    labelPosition: "ABOVE",
                    data: index(
                      local!distinctUsers,
                      wherecontains(
                        touniformstring(fv!item),
                        touniformstring(local!distinctUsers.Group)
                      )
                    ),
                    selectable: true,
                    selectionValue: local!selection,
                    selectionSaveInto: {
                     
                      local!selection,
                   
                      a!save(local!selectedRows, append(local!selectedRows, fv!selectedRows)),
                     
                      a!save(local!selectedRows, difference(local!selectedRows, fv!deselectedRows))
                    },
                    columns: {
                      a!gridColumn(
                        label: group(
                          groupId: togroup(fv!item),
                          property: "groupName"
                        ),
                        value: fv!row.Members
                      ),
                      a!gridColumn(
                        value: a!richTextDisplayField(
                          value: a!richTextIcon(
                            icon: "times",
                            caption: "Remove User",
                            color: "NEGATIVE",
                            size: "MEDIUM",
                            link: a!dynamicLink(
                              value: fv!row.Members,
                              saveInto: {ri!userToRemove,
                              a!removeGroupMembers(
                                group: local!selectedRows.Group,
                                members: local!selectedRows.Members
                              )
                            }
                            )
                          )
                        ),
                        width: "ICON"
                      )
                    },
                    pagingSaveInto: local!pagingInfo
                  )

Children
No Data