Trouble with editable_if based on user roles

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:
3X_1_e_1e19743154d20a291caad607bc7c66adafe5130a.png

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 Solved
0 2 397
1 ACCEPTED 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!

View solution in original post

2 REPLIES 2

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!

Top Labels in this Space