I am looking for a solution for the scenario where mobile users are assigned to several locations that are at different levels in the organizational structure.
In one of our project spaces we have set up an organization structure with 6 levels (Country > State > District > Blocks > Cluster of villages > Villages). The two lowest levels are set to be case owners. It can now happen that a mobile user has 2 locations assigned: one location in the "cluster of villages" level and one location in the "villages" level.
The solution described on the CommCare Help Site (https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143973145/Advanced+Organization+Level+Configuration#Making-select-questions-with-locations-as-choices) does not work in this case, because I have 2 different “Types of location”. I tried several things (e.g., setting several filters and not only one), but I was not able to create the solution I have in mind: that only the 2 exact locations the user is assigned to are shown as options to select.
Can someone explain to me if there is a solution to my problem, and if so, what the solution is?
Thanks for your support!
are you saying that you wish for locations that have different types to show up in your same list?
add a filter and use "or"
Hi @Mazz
Let's say the user is assigned to "Cluster of villages A" (with villages A1, A2 and A3) and at the same time to a village B5 (which is one of the villages under the "Cluster of villages B") I want the user will see 2 options in the lookup table question:
- Cluster of villages A
- Village B5
So, yes, I want that 2 different types of locations are displayed.
The "or" filter you mentioned will ultimately show me all villages from Cluster A and B and also the "Cluster of villages B". This is too much. I only want to see the exact locations the user is assigned to.
I hope now it's clearer.
it shouldn't if your mobile worker is has the right location assignments.
they would only see all the villages from cluster B if they are placed in a location that has that cluster as child locations.
if your user is not supposed to see all the villages in cluster B, then those villages should not show up at all. if they are, try deleting user data and syncing again. it might be some old rows that did not get cleared.
The type filter should be the "Type code" in the org levels.
on the other hand, if your mobile worker is set to be in a level higher than the B cluster, and there is a line from that node to the B cluster, then you want to check the flags around these
as they have an impact on which cases and levels show up.
if your structure looks like
- Level 1 (loc A)
Level2 (A_1)
Level2 (A_2)
Level 1 (loc B) - Level2 (B_1)
and your mobile worker is in the locations with the "*", then by default if you filter for locations of the type "Level 1" you will only get Loc A
If you filter for location types "Level 2" you should get A_1, A_2, and B_1.
if you are not, check out the flags include without expanding and and expand to
Thanks, @Mazz for your detailed answers.
Let me show what I have done:
This is the organisation structure (it deviates a bit from what I described above, the idea should be clear). The locations with the red rectangle are those that I assign to a mobile user.
Here you see the test user profile:
The lookup table question in my registration looks like that:
And this is how the form appears on the app preview with my test user account logged in.:
As you can see I can assign all locations of level 2 and level 3. That's not what I want. I would only want to see "Test Level A1" and "Test Level A2a" as options to select from.
I cleared the user data and did a sync. It doesn't change.
The instance('locations')
fixture contains all locations that are made available to the user, which by default includes all direct ancestors and descendants of their locations. The locations your user is directly assigned to are available in this variable:
instance('commcaresession')/session/user/data/commcare_location_ids
So to select between them, you should be able to use an expression like this:
instance('locations')/locations/location[
selected(instance('commcaresession')/session/user/data/commcare_location_ids, @id)
]
I think I understand now what the need is
you basically only want the locations that the mobile workers is assigned to to show up and nothing else.
this is not standard behavior - permissions are hierarchical. so, the behavior you are showing here is what is expected.
Ethan's suggestion will give you the same result if I understand correctly "the mobile worker's list of locations they have access to include all the locations under A1 LV2.
I suspect that you wish some other mobile workers see ALL the locations under A1 lv2, right? if so, you have a problem.
if not, go to this page
click on advanced to see the other fields, and change "level to expand to" and make it lv2.
this will mean that if you wish for locations under A1 lv2 "lv3" to show up for mobile workers, you need to assign them to those locations as well as the A1 lv2.
You can also filter by ancestor type, so if you could also do something like this:
instance('locations')/locations/location[@type="level-3"][
selected(instance('commcaresession')/session/user/data/commcare_location_ids, @level-2_id)
or selected(instance('commcaresession')/session/user/data/commcare_location_ids, @id)
]
That will give all level 3 locations that the user is assigned to and those that are children of the level 2 locations the user is assigned to. Depending on the specifics of your user management setup and case ownership needs, you could do many variations of that same idea.
Hi @Mazz and @Ethan_Soergel , thank you for your continued and very helpful support. I tried out your suggestion
instance('commcaresession')/session/user/data/commcare_location_ids
and it has worked. After clearing user data and sync'ing again, only the locations the user is assigned to appear as answer options. So, for now my issue is solved.
Thank you so much!
just to ensure that it doesn't act funny later, move your mobile worker around and sync a few times and see if locations update accordingly if you do not clear user data - just so that you know what to tell your users when the time comes
Will do so. Thanks, @Mazz