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

  • 0
    Certified Senior Developer

    a!dynamiclink(
    saveInto: a!removeGroupMembers(
                                group: "Your Group",
                                members: fv!row.Members/"Current member you want to remove",
                              
                              ))
                              
                              
                            
    a!dynamiclink(
    saveInto: a!addMembersToGroup(
                                group: "Your Group",
                                newMembers: /"Current member you want to add",
                              
                              ))

    Use a!removeGroupMembers() and a!addMembersToGroup() in save into param of dynamic link. Interface Configuration needs to look like above. 

    I suggest going with initiating a Process cause it helps in future references (It provides history of who did it). In process model use respective smart services

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

  • Ok  Thank You. Now I am go with the process as you suggest.