Error while deleting multiple user from grid

a!localVariables(
  local!selectionValue,
  local!isUserSelected: runtimetypeof(local!selectionValue) = 'type!{http://www.appian.com/ae/types/2009}User',
  local!actionTaken: if(
    isnull(ri!btnAction),
    false,
    or(ri!btnAction = "ADD")
  ), 
  local!navigationLength: if(
    isnull(ri!navigationPath),
    0,
    length(ri!navigationPath)
  ),
  a!formLayout(
    label: "User Management",
    contents: {
      a!pickerFieldGroups(
        label: "Select a group to view its members",
        maxSelections: 1,
        value: ri!initialGroup,
        saveInto: {
          ri!initialGroup,
          a!save(
            {
              ri!btnAction,
              ri!addedToGroup,
              ri!removeFromGroup,
              ri!navigationPath,
              local!selectionValue
            },
            null
          )
        }
      ),
      a!sectionLayout(
        label: group(ri!initialGroup, "groupName") & " Members",
        contents: {
          a!buttonLayout(
              a!buttonWidget(
                label: "Remove Member",
                value: a!removeGroupMembers(
                  members:ri!removeFromGroup
                ),
                saveInto: {
                  ri!btnAction,
                  a!save(ri!userToRemove, local!selectionValue),
                  /*
                    Since a user needs to be removed from a group, the button
                    needs to determine what group the user should be removed from.
                  */
                  a!save(
                    ri!removeFromGroup,
                    if(
                      /* If the user is on the first column, save the initial group */
                      local!navigationLength = 1,
                      ri!initialGroup,
                      /* Otherwise save the group containing the selected user */ 
                      ri!navigationPath[local!navigationLength - 1]
                    )
                  ),
                  /*
                    This navigation path will be used to pre-populate the group browser
                    when the user returns to this interface after the selected user has
                    been removed. Therefore, we must remove the selected user from the
                    navigation path to prevent an error.
                  */
                  a!save(ri!navigationPath, rdrop(ri!navigationPath, 1))
                },
                submit: true,
                color: "NEGATIVE",
                disabled: or(ri!btnAction,(local!selectionValue)),
              )
          ),
          a!sectionLayout(    
            label: "",
            contents: {
              a!gridField(
                labelPosition: "COLLAPSED",
                data: a!groupMembers(
                  group: ri!initialGroup
                ),
                columns: {
                  a!gridColumn(
                    label: "Group Members",
                    value: fv!row,
                    sortField: "displayName"
                  )
                },
                pagingSaveInto: null,
                borderStyle: "STANDARD",
                selectable: true,
                selectionStyle: "CHECKBOX",
                selectionValue: local!selectionValue,
                selectionSaveInto: local!selectionValue
              )
            }
          ),
          a!linkField(
            labelPosition: "COLLAPSED",
            links: {
              a!dynamicLink(
                label: "+ Add Users to " & group(ri!initialGroup, "groupName"),
                value: "ADD",
                saveInto: {
                  ri!btnAction,
                  a!save(ri!addedToGroup, ri!initialGroup)
                }
              )
            },
            showWhen: not( local!actionTaken)
          )
        },
        showWhen: not(isnull(ri!initialGroup))
      ),
      a!sectionLayout(
        label: "Add Users to " & group(ri!addedToGroup, "groupName"),
        contents: {
          a!pickerFieldUsers(
            label: "Users to Add",
            value: ri!usersToAdd,
            saveInto: a!save(ri!usersToAdd, getdistinctusers(save!value)),
            required: true
          )
        },
        showWhen: ri!btnAction = "ADD"
      ),
      a!buttonLayout(
        primaryButtons: {
          a!buttonWidget(
            label: if(ri!btnAction = "ADD", "Add Users", ""),
            submit: true,
            style: "SOLID"
          )
        },
        secondaryButtons: {
          /*
            Allows the user to cancel the selected action. If the user
            cancels out of the action, we need to clear all the
            selection variables
          */
          a!buttonWidget(
            label: "Cancel",
            value: null,
            saveInto: {
              ri!btnAction,
              ri!userToRemove,
              ri!addedToGroup,
              ri!removeFromGroup,
              ri!usersToAdd,
              local!selectionValue
            },
            style: "OUTLINE",
            showWhen: local!actionTaken
          )
        },
        showWhen: local!actionTaken
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Close",
          value: "CLOSE",
          saveInto: ri!btnAction,
          submit: true,
          validate: false
        )
      }
    )
  )
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    It feels like you're using some of these components without fully understanding what they actually do.  I understand it's part of the learning process, though generally I'd recommend starting simpler and building up from there, making sure you understand what the code is doing before stepping up to the next level of complexity.

    In the case of your "remove users" button though, per what Stefan mentioned, you have a simple mix-up.  For an action button like this, the "value" parameter is arbitrary and often not needed at all (like in your case).  The "remove group members" function, as is mentioned in the documentation, needs to go *directly in the SaveInto*.

      a!buttonWidget(
        label: "Remove Member",
        /* value: a!removeGroupMembers(
          members:ri!removeFromGroup
        ), */
        saveInto: {
          /* ri!btnAction, */  /*probably not needed */
          /* a!save(ri!userToRemove, local!selectionValue), */  /* also probably not needed */
          a!removeGroupMembers(
            group: ri!initialGroup,
            members: local!selectionValue
          )
        }
      )

  • I understood mike. I will start simpler and understand it.

    Taking it as part of learning.

    Thanks for the solution and guidance.

Reply Children
No Data