Skip to main content
September 27, 2023
Question

a!forEach Not Working When Items Comes from Local Variable

  • September 27, 2023
  • 1 reply
  • 0 views

I have a local variable that holds an array. When I pass this local variable to a a!forEach items, it does not loop. When I take the array value and paste it directly into items, it works. Why is it not working when I pass in the array from the local variable?

a!localVariables(
  local!groups: {
    cons!AX_ALL_USERS,
    cons!AX_MECHANICS,
    cons!AX_REGISTRARS,
    cons!AX_SUPERVISORS,
    cons!AX_ADMINISTRATORS_POINTER
  },
  {
    a!sectionLayout(
      label: "Groups for " & loggedInUser(),
      contents: {
        a!gridField(
          label: "",
          labelPosition: "ABOVE",
          data: todatasubset(a!forEach(
            /* WORKS */
            items: {
              cons!AX_ALL_USERS,
              cons!AX_MECHANICS,
              cons!AX_REGISTRARS,
              cons!AX_SUPERVISORS,
              cons!AX_ADMINISTRATORS_POINTER
            },
            /* DOES NOT WORK */
            /*items: local!groups,*/
            expression: {
              {
                groupName: group(fv!item, "groupName"),
                isMember: a!isUserMemberOfGroup(loggedInUser(), fv!item)
              }
            }
          ), fv!pagingInfo),
          columns: {
            a!gridColumn(label: "Group Name", value: fv!row.groupName.),
            a!gridColumn(label: "Member?", value: fv!row.isMember)
          },
          validations: {}
        )
      }
    )
  }
)

    1 reply

    stefanhelzle0001
    Brainy
    September 27, 2023

    Your code, adapted to some of my groups, works as expected.

    Could it be that you created that local variable later on, and did never hit the TEST button or refreshed the browser tab to allow Appian to evaluate the value assignment to that local?

    When you add an empty local variable, and add a value later on, Appian will not automatically refresh that.