Assign mobile workers to multiple locations

When implementing an organizational structure, it seems that you can assign a mobile worker to multiple locations. See the link and picture below:

https://confluence.dimagi.com/display/commcarepublic/Assigning+Mobile+Workers+to+a+Location

Does that mean if cases are assigned to a location for example:

Location1

  • Case1
  • Case2

Location2

  • Case3
  • Case4

Then a mobile worker is assigned to both Location1 and Location2, will that mobile worker be able to access all the cases assigned to those locations (Case1, Case2, Case3, Case4) or only the cases at their Primary location?

@Ethan_Soergel
@Simon_Kelly
@erobinson

I just tested it out, and I believe the behavior is this:

Users will only receive cases owned by locations whose level is tagged "Owns Cases", and they'll receive all such cases if assigned multiple locations.

However, if your user is in multiple case sharing locations, then you might see an error in registration forms that says

The case sharing settings for your user are incorrect. This user must be in exactly one case sharing group. Please contact your supervisor.

You can resolve this by creating a hidden value in your registration form with the calculate expression
instance('commcaresession')/session/user/data/commcare_location_id
And then save this to the case property owner_id. That'll tell CommCare to use the user's primary location as the case owner.

Thank you so much for your response @Ethan_Soergel its very much appreciated! I will come back to to this post as soon as we have been able to test this out.

I had 2 other posts that I needed answers to, however I posted them in the developers section. Should I have rather of posted them in the users section? Here are the links below:

Thank you again for your assistance!

if you want to have a little more control over that, you can populate a lookup table question with the locations that the user has access to and have them select one to update the owner_id.

it's a little funny and DANGEROUS because the app doesn't care what you put in there. it will stop throwing that "belongs to more than one case sharing group" error as soon as it sees that you are updating owner_id. so there is a significant room here to destroy your case and becoming unable to see it anywhere.

Additionally, if you have a "view child locations" option ticked on a parent location to the one the mobile worker is in or has access to, you'll also see that the form will load the lineage tree into the "locations" meta. can be confusing - the level to expand to and from settings in the advanced options

it is important to note also that this error will only show up in forms that create cases. So unless the user that has multiple location access needs to create cases, you don't need to worry about it.

my two cents

Thank you for that extra information @Mazz. That's really helpful actually. I havent had time to get to a proof of concept yet, but the idea is to have an organization structure to control the location hierarchy. For example:
Country
Region
District
FDP (Food Distribution Point)

Cases would then have their owner_id set to the FDP id. So in essence cases would belong to a FDP location. I have done this before in a previous project and it worked well, however in that scenario a mobile worker only needed to see cases from 1 FDP location. I am now looking at a project where a mobile worker needs to be assigned to multiple FDP locations and not necessarily a District location directly above it as a parent. So its really helpful to know that I will be able to achieve this.

This actually leads me to my next question, as we dont intend the mobile workers to create the cases via the mobile app at all, but rather we would be creating the cases from a .net webapp via the API.

I have created a separate thread for that though here:

@erobinson

1 Like

Thanks for bringing this up, @Calvin. I have had same situation assigning mobile users multiple locations .
Users will only view but can't update any form due to case sharing error.

Am following keenly on responses from our able dev @Ethan_Soergel and @Mazz

@Kiptoos did @Mazz and my suggestions not resolve the issue in your use case? Can you elaborate?

this is the solution to your error. the rest of the comments describe what to do to have a choice over who the owner id belongs to

Hi guys,

So I have run into this error on a registration form even though I am setting the owner_id case property to a hidden calculated field on the form.

The one big difference to the question above though is that this mobile worker has been assigned a "case sharing group" and has a primary location assigned as the 1st app using the organization structure and the 2nd app makes use of case sharing groups.

Is there a way around this error or does that mean that a mobile worker cannot belong to a case sharing group and a location from an organization structure?

So in essence he would have to have 2 different mobile workers for each app? One assigned to a case sharing group and another assigned to a location.

Any info would be greatly appreciated.

Kind Regards,

@Ethan_Soergel
@Simon_Kelly
@Norman_Hooper
@Mazz
@erobinson

I misunderstood your post initially

ok so this is a new one for me. you need the groups for the app permissions, but you need the org structure for case management.

I was not aware that this is going to be an issue but this is giving me a heads up for an upcoming project.

ok so basically we are saying that being in both is confusing the form and that the usual updating owner_id trick is not working. that's really odd cause I've had forms run with owner_id being updated to blank value.

I can't seem to find it but there's another fixture called groups. maybe if instead of trying to use the org structure in your form you can try to use the groups fixture and see if that has an affect? in theory, the groups fixture will contain the locations as well if I remember correctly. I did this years ago trying to understand the error and case sharing options so it's a little hazy