I have some forms built in an app. I have multiple users to access and use the application and all forms. Now I want to hide a particular form (example: Test) from a user "ABCD". I am not aware how to do that. Kindly guide me how to do that.
···
On Mon, Dec 26, 2016 at 6:09 AM, Khan, Afroz wrote:
Hi,
I have some forms built in an app. I have multiple users to access and use
the application and all forms. Now I want to hide a particular form
(example: Test) from a user “ABCD”. I am not aware how to do that. Kindly
guide me how to do that.
you can still use display conditions, but you have to reference user properties or session data.
Option 1:
contains('username_1 username_2', instance('commcaresession')/session/context/username) in the display condition of a caselist will hide this caselist from anyone except username_1 and username_2
Option 2:
you can also have a user property "is admin" or something else that you create against your users, and use an expression like this
if(count(instance('commcaresession')/session/user/data/is_admin) > 0, 1, 0)
this expression will return "1" if the user has the property "is_admin" filled for the current user record that's logged in. 1 is true, and so it will show the caselist.
Option 3:
yet an even more fancy option is to leverage organizational structure and locations.
in this expression, i'm checking what location the user is in, and then checking what type of location it is "what level" and if it's a field supervisor, return true.
you should use the first option if you're doing something quick and dirty and you don't expect to have to change the users that can see the form. i.e. short application use or for testing purposes.
you should use the second option if you do not leverage the organizational structure/hierarchy that commcare provides.
and i personally recommend using the third option as it leverages the built in functionality to organize your mobile workers and case data. this also minimizes the need to change individual user records in order to accomplish this. you can just add users to a location and if that location is a supervisor/whatever you want location then show the forms.