Switch of roles not working

Hi everyone!

I have a problem in my switch.

Captura0.PNG

I try to distinguish among some roles: admin, inspect, technician, employee:

admin: ALL_CHANGES
inspect: ALL_CHANGES
employee: READ_ONLY
technician: ADDS_AND_UPDATES

Captura1.PNG

Show More

The app distinguishes among the roles well. And it is shown with buttons with different actions depending on whether the user can add, edit or delete.

Ok, that's perfect, but the problem is that when an admin or inspect try: add, edit or delete the app fails. For example, when I add a register with a admin user:

 

Captura2.PNG

I waited a minute but not working, so I push on this button, and:

Captura3.PNG

Unable to add row to table 'Residuos'. โ†’ Table 'Residuos' does not allow this operation. Expression result: 'READ_ONLY'. Expression Trace: {"key": "SWITCH(ANY(SELECT(Usuarios[role],([EMAIL] = USEREMAIL()))),\"administrador\",\"ALL_CHANGES\",\"inspector\",\"ALL_CHANGES\",\"empleado\",\"READ_ONLY\",\"tecnico\",\"ADDS_AND_UPDATES\",\"READ_ONLY\")","result": "READ_ONLY","values": []}

I
think that my switch is ok, but i don't know why the app fails to add a register with admin

Thanks!

Solved Solved
0 19 723
3 ACCEPTED SOLUTIONS

When you have table like what I have done, you can change the user access based on access what you give.  secondly all those access can be edit or changed in the app interface. you need not change in table properties like switch(). 

It is kind of dynamic user controls. all amendments I do in app itself. I will not change in properties. 

jaichith_0-1693480458932.pngjaichith_1-1693480496292.pngjaichith_2-1693480523250.png

jaichith_3-1693480565409.png

 

View solution in original post

there will be 4 tables usually,

1. Users (Organisation Members)

2. Users Roles ( Admin, Manager etc)

3. User Permission ( What admin hold like All changes, Sales person only Adds_AND _ UPDATES etc)

4. Access or Permission Types - optional (It is like Adds_AND _ UPDATES, delete only etc)

This enables you to have like ERP software ๐Ÿ˜€

jaichith_4-1693481000436.png

 

 

View solution in original post

19 REPLIES 19

As the error description shows , it sounds that the expression is evaluating to "Read_only" result. You may want to double check the email of the user adding the row is evaluating for a role other than admin, inspector or technician which allow adds to the table. Possibly a spelling mistake in roles in the table or in the expression or a small mismatch in email id entered in the Usuarios table than the actual email.

I have tried with different emails from the users of the application and it keeps failing me.

This is the table in google sheets:

Captura4.PNG

Captura7.PNG

So, i tried add a register with testapp@gmail.es

Captura56.PNG

Thank you for sharing all the details. Those are really good.

As per my understanding it should work.  My testing also showed it works for me with exactly similar expression. Someone else may have a better input.

One thing, you may want to simply check without the expression,  if you are able to add a record. with "Add Update Delete" enabled for all roles of users as follows.

Suvrutt_Gurjar_0-1693227166761.png

 

I don't understand why that expression doesn't work.

One thing that surprises me when using the expression is that it warns me about: 

"This formula is not evaluated in the context of a row, so column values are not available."

Captura8.PNG

I hope someone else contributes some ideas, because I can verify without the expression, but the objective of having different user roles is that the app distinguish the actions that each user can do. Thank you very much anyway!

That  warning you have highlighted is a standard warning for certain settings such as view display names , localization settings and this setting. However in this case the expression uses USEREMAIL() to identify the record in the USUARIOS table, so it is not a problem.

One thing.. open the upper left hamburger menu from the emulator and check what email address you are using with the login.

Hi Aleksi!

You mean this hamburguer menu?

Captura11.PNG

I have tried disconnecting the user "justin@sample.com". I get a disconnection confirmation, I click on disconnect, but that user does not disconnect

This is the reason why your formula didn't work. Close all browser tabs where you have AppSheet opened. Logout from your AppSheet account. Then clear the browser's cache. Finally login to AppSheet and open the editor again and see if it now shows the correct email address.

I have tried to do what you told me. I managed to log out of "justin@sample.com" but I couldn't connect to any users in my app, when I pressed the "log in" button in the sidebar, the bar was hidden. After a while using the application I looked at the sidebar and I had a user of my application that I had tested with a while before (it was not the same user I was testing with at that moment)

Hi Jaichith!

Thank you for sending your thread, I think it can be useful!

I read your thread, but to do what you propose here I should have 3 different tables, right?

Maybe I could do it with my only "Users" table?

When you have table like what I have done, you can change the user access based on access what you give.  secondly all those access can be edit or changed in the app interface. you need not change in table properties like switch(). 

It is kind of dynamic user controls. all amendments I do in app itself. I will not change in properties. 

jaichith_0-1693480458932.pngjaichith_1-1693480496292.pngjaichith_2-1693480523250.png

jaichith_3-1693480565409.png

 

there will be 4 tables usually,

1. Users (Organisation Members)

2. Users Roles ( Admin, Manager etc)

3. User Permission ( What admin hold like All changes, Sales person only Adds_AND _ UPDATES etc)

4. Access or Permission Types - optional (It is like Adds_AND _ UPDATES, delete only etc)

This enables you to have like ERP software ๐Ÿ˜€

jaichith_4-1693481000436.png

 

 

BRO THANK YOU SO MUCH! Thanks to this solution and your thread I have been able to solve my problem, I already know that the switch here is useless and that I really have to do this. Thank you very much again.

Yes , switch () is nearly useless. 

Deploy Dynamic User Access and if you wish to disable (making not visible) any view to any user roll then use the lookup expression <> "No Access" in showif option of particular UX - VIEW.

 If you have any trouble in implementing this let me know. 

Thanks for accepting my reply as solution. 

Ok, I need help with this, I want to make the permissions table only visible to the admin

Go to the UX of the table "Permissions" and in it there will be property called Showif . Use same lookup formula and include " <> "No Access" " in the expression.

Example : Lookup(.....) <>  "No Access"

In the dataset if "No Access" given to other users other than Admin. They cannot see the Table view. 

For Admin give it as ALL_CHANGES

 

Screenshot_2023-09-05-00-10-34-32_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

โ€ƒ

Screenshot_2023-09-05-00-11-09-80_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

โ€ƒ

Please have a look.

I got it! THANK YOU!

Top Labels in this Space