I have successfully implemented user roles, based upon the Current_User slice approach from @MultiTech_Visions. I even posted in Tips & Tricks describing how I have set up Flexible user role management. However Iโm adding a specific bit of additional security using an Editable_If expression and it is giving me trouble.
To explain what I want to do, I have four user roles, โUserโ, โSuper Userโ, โAdminโ and โSuper Adminโ. I have a user management form which is only shown to those user who belong to a role which has access to that table (controlled through my flexible user role management approach). This all works fine and it means that both โAdminsโ and โSuper Adminsโ can edit users. However, I want to restrict the form further so that only a โSuper Adminโ can change the role of a โSuper Adminโ. I canโt get the Editable_If expression to do what I need.
This is what I have tried:
OR([Role ID].[Value]<>"Super Admin",INDEX(Current_User[Role ID], 1)=[Role ID])
This validates in the expression builder, but if I hit Test I get the following:
I also tried:
OR([Role ID].[Value]<>"Super Admin",INDEX(Current_User[Role ID], 1)="Super Admin")
It also validates but gives the same error on test.
As a workaround, I created a VC called Role on the user table (also brought through to the current user slice) which takes the value from the role ID enum field and stores it as text. If I write the following expression:
OR([Role ID].[Value]<>"Super Admin",INDEX(Current_User[Role], 1)="Super Admin")
It evaluates correctly and the test and Editable_If expression do exactly what I need.
What I donโt understand is why I canโt get the expression to work with Role ID (the enum field) and am having to resort to creating and referencing a virtual column.
Solved! Go to Solution.
Well I managed to solve it! I simply wrapped both parts of the comparison in TEXT() and it works:
OR(
[Role ID].[Value]<>"Super Admin",
TEXT(INDEX(Current_User[Role ID], 1))=TEXT([Role ID])
)
I got the clue from the error message which suggested there was a problem with the object types, so I thought Iโd allow them to be converted to text implicitly and it worked. I still donโt understand though why the [Role ID] column in the user table which is being updated does not appear to have the same object type as the [Role ID] in the current user slice of the same table!
Well I managed to solve it! I simply wrapped both parts of the comparison in TEXT() and it works:
OR(
[Role ID].[Value]<>"Super Admin",
TEXT(INDEX(Current_User[Role ID], 1))=TEXT([Role ID])
)
I got the clue from the error message which suggested there was a problem with the object types, so I thought Iโd allow them to be converted to text implicitly and it worked. I still donโt understand though why the [Role ID] column in the user table which is being updated does not appear to have the same object type as the [Role ID] in the current user slice of the same table!
User | Count |
---|---|
17 | |
14 | |
10 | |
7 | |
4 |