Using a lookup table in a display condition

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?

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

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.

I was looking for the same kind of thing. I wanted to reference a lookup table on the display condition of the form/module and I found it here and here:

  • Referencing lookup tables on a form display condition uses a slightly different syntax than in app-builder. Here are some examples :
  • instance('item-list:country')/country_list/country/id != "kenya"
  • instance('item-list:user_permissions')/user_permissions_list/user_permissions[user_role=#session/user/data/user_role]/f_register_household = '1')