How to get user’s location ID for use in form display logic in CommCare

commcare

How can I get the user's location id for use in form display logic? I know you can get the user id from the session, but are all the user properties there?

Best Answer

You can do this by accessing a user's Custom User Data.

To access the user's primary location, use this:

instance('commcaresession')/session/user/data/commcare_location_id 

If the user is assigned to multiple locations, you can use this to get a space separated list of location ids:

instance('commcaresession')/session/user/data/commcare_location_ids