# Assign mobile workers to multiple locations

**URL:** <https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966>\
**Category:** Users\
**Created:** [July 14, 2023, 1:18pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966 "2023-07-14T13:18:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calvin](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/calvin/32/938_2.png) [@Calvin](https://forum.dimagi.com/u/Calvin)\
**Post date:** [July 14, 2023, 1:18pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/1 "2023-07-14T13:18:14Z")

</div>

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](https://confluence.dimagi.com/display/commcarepublic/Assigning+Mobile+Workers+to+a+Location)

 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/0/078856b165177de07cab60ad1e978e745afc5165.png)

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

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [July 14, 2023, 2:39pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/2 "2023-07-14T14:39:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Calvin](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/calvin/32/938_2.png) [@Calvin](https://forum.dimagi.com/u/Calvin)\
**Post date:** [July 18, 2023, 7:00am UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/3 "2023-07-18T07:00:22Z")

</div>

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:

> [@Create or Edit the Organizational Structure (Location Data) via the API](https://forum.dimagi.com/t/create-or-edit-the-organizational-structure-location-data-via-the-api/9965):
>
> There doesnt seem to be any information given on the organizational structure (or location data as its sometimes referred) under the documented APIs. See link below [https://confluence.dimagi.com/display/commcarepublic/CommCare+HQ+APIs](https://confluence.dimagi.com/display/commcarepublic/CommCare+HQ+APIs) However I know its possible to pull the location data via the API as we have done so in another project we have worked on. However what I am needing to know is it possible to create or even just update location data via the API? I see there was a similar post pr…

> [@Create or Edit web users via the API?](https://forum.dimagi.com/t/create-or-edit-web-users-via-the-api/9964):
>
> Is it possible to create or edit web users via the API? Create (wondering if it is possible because of the way a new web user is invited to join the project space) Edit a web user would be changing their name or updating their role etc. I see that its possible to pull a list of web users via the API, but that looks like where it ends. See the link below which gives a list of the documented APIs. [https://confluence.dimagi.com/display/commcarepublic/CommCare+HQ+APIs](https://confluence.dimagi.com/display/commcarepublic/CommCare+HQ+APIs)@Ethan_Soergel@Simon_Kel…

Thank you again for your assistance!

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [July 19, 2023, 8:17am UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/4 "2023-07-19T08:17:45Z")

</div>

> [@Ethan\_Soergel](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Calvin](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/calvin/32/938_2.png) [@Calvin](https://forum.dimagi.com/u/Calvin)\
**Post date:** [July 19, 2023, 2:07pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/5 "2023-07-19T14:07:52Z")

</div>

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:

> [@Bulk upload case data via the API to create new cases](https://forum.dimagi.com/t/bulk-upload-case-data-via-the-api-to-create-new-cases/9987):
>
> So the overall plan here is that mobile workers would not be creating the cases, but rather we would be creating the cases from a .net webapp via the API. These cases would be owned by a location using an organizational structure and setting the owner\_id of the case so that mobile workers assigned to a location will be able to access the cases. The mobile workers would then need to be able select a case from a case list within the commcare app and make updates to it via a followup form. The org…

@erobinson

---

<div class="post-metadata">

**Author:** ![Kiptoos](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/k/dbc845/32.png) [@Kiptoos](https://forum.dimagi.com/u/Kiptoos)\
**Post date:** [July 21, 2023, 1:00pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/6 "2023-07-21T13:00:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [July 21, 2023, 2:14pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/7 "2023-07-21T14:14:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [July 24, 2023, 8:24am UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/8 "2023-07-24T08:24:27Z")

</div>

> [@Ethan\_Soergel](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Calvin](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/calvin/32/938_2.png) [@Calvin](https://forum.dimagi.com/u/Calvin)\
**Post date:** [February 27, 2024, 10:55am UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/9 "2024-02-27T10:55:16Z")

</div>

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.

 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/4/484a7e1853ba0bb760a47d11a669fa9c10160acc.png)

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

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [February 27, 2024, 1:26pm UTC](https://forum.dimagi.com/t/assign-mobile-workers-to-multiple-locations/9966/11 "2024-02-27T13:26:25Z")

</div>

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
