How can I search groups for an attribute value

Hello,

I have a requirement to retrieve a value (CustomerCode) for a signed in user based on a group attribute. When a user logs in, we will be using this value for row level security.

The problem is that users can belong to multiple groups, and not all the groups have the attribute value CustomerCode. 

The only way I have been able to do this is using the unsupported try function which I know is not acceptable. getgroupattribute returns an exception if the attribute does not exists.

a!localVariables(
  local!a: "mpierson",
  local!b: getgroupsformemberuser(local!a),
  local!d: a!forEach(
    items: local!b,
    expression: if(
      try(
        fn!getgroupattribute(fv!item, "CustomerCode"),
        ""
      ) <> "",
      fn!getgroupattribute(fv!item, "CustomerCode"),
      {}
    )
  ),
  local!d
)

Is there a supported way to handle exceptions? 

Is there a better way to store attributes for groups of users? We are trying to not have to maintain at the user level.

  Discussion posts and replies are publicly visible

Parents
  • I think I figured it out. Here I am using the getgroupsoftypefromlist to weed out the groups that do not have the attribute that I need.

    a!localVariables(
      local!user: fn!loggedInUser(),
      local!userGroups: getgroupsformemberuser(local!user),
      local!grouptype: fn!getgroupsoftypefromlist(local!userGroups, "Customers"),
      local!CardCode: a!forEach(
        items: local!grouptype,
        expression: if(
          fn!getgroupattribute(fv!item, "CardCode") <> "0",
          fn!getgroupattribute(fv!item, "CardCode"),
          {}
        )
      ),
      local!CardCode
    )

Reply
  • I think I figured it out. Here I am using the getgroupsoftypefromlist to weed out the groups that do not have the attribute that I need.

    a!localVariables(
      local!user: fn!loggedInUser(),
      local!userGroups: getgroupsformemberuser(local!user),
      local!grouptype: fn!getgroupsoftypefromlist(local!userGroups, "Customers"),
      local!CardCode: a!forEach(
        items: local!grouptype,
        expression: if(
          fn!getgroupattribute(fv!item, "CardCode") <> "0",
          fn!getgroupattribute(fv!item, "CardCode"),
          {}
        )
      ),
      local!CardCode
    )

Children
No Data