Restrict app forms to user types

It’s possible that you can allow forms to appear for certain contacts by defining expressions in the properties.json file of the respective form (see screenshot). However, is it also possible to allow forms to only appear for certain users who are logged into the CHT app (e.g. supervisor or admin)? If yes, how is this defined in the “expression” part of the properties.json file?

1 Like

You can reference user properties in the expression. So something like user.role === 'chw' would restrict the form to only users with the chw role.

2 Likes

To add to @jkuester’s answer above:

It might not be immediately clear that the user properties being referenced in the form expression are actually sourced from the user’s associated contact document.

For example, if your user’s role (visible in the user management) is chw, but the associated contact does not have a field named role with value chw, it will not work as expected. In that case, please make sure that you have the correct role in the contact document too.

3 Likes

@binod Thank you very much for your clarification. This worked perfectly.

2 Likes

A post was split to a new topic: Limit access to forms based on Health District ID