Using a lookup table in a display condition

(Norman Hooper) #1

I am pretty sure that a lookup table instance needs to be set in a form in order to use that lookup table in that form, so I believe the answer to the following question is “No” … but I’d like to make sure:

Is there a way to use a lookup table in a menu display condition?

I would like to use something like:

instance('user_roles')/user_roles_list/user_roles/[name=#user/role]/can_see_foo_menu = 1

My fallback is to hardcode the user roles, like …

#user/role = 'admin' or #user/role = 'supervisor' or ...

… but there are many roles, and several menus with display conditions. We would also like to be able to add roles without changing the app, so this is definitely something I’d prefer to avoid.

Any ideas?

0 Likes

(Michel Akkaoui - de Sousa) #2

I’m not sure if you can do something like that. Did you try it ?

An alternative solution is to use custom user data.
https://wiki.commcarehq.org/display/commcarepublic/Custom+User+Data

You can set a new field on the user level such as “can_see_foo_menu” that can be filed with ‘yes’ or ‘no’.
Then your form or module display condition would be :
instance('commcaresession')/session/user/data/can_see_foo_menu = 'yes'

When adding a new user you will need to complet an additional field, but you can add roles without changing the app.

-Michel

0 Likes

(Norman Hooper) #3

Thanks @Michel_Akkaoui_de_So! I think custom user data is a great alternative. (I also think my first attempt might have failed because of an XPath error.) Either way, your help is very useful, and I’m sure we can do this in a way that doesn’t require app changes.

0 Likes