Retrieving mobile worker's location from organisation hierarchy

45 views
Skip to first unread message

Alexandre Vanobberghen

unread,
Oct 31, 2015, 3:30:11 AM10/31/15
to commcare-users
Hello,

I have an organisation with the following levels: Country / Zone / Province / District / Health Facility. I have also assigned mobile workers to these locations.
I am now trying to retrieve the mobile worker's country and assign it to a form variable. What would be the syntax to do so please?

Thank you,

Alex

Cory Zue

unread,
Nov 1, 2015, 5:59:54 AM11/1/15
to commcar...@googlegroups.com
Hello,

The syntax is quite ugly, unfortunately. Additionally, it requires that you assign all users to the same level of the hierarchy (and depends on that hierarchy). We are hoping to extend formbuilder to do this more seamlessly in the future, but for the time being, the following page might help.


cheers,
Cory

--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexandre Vanobberghen

unread,
Nov 2, 2015, 2:41:38 AM11/2/15
to commcare-users
Hello Cory,

Thanks for your response.
All my users are assigned to health facilities i.e. the lowest level of the hierarchy.
I tried to use the link you sent to formulate the following syntax:

instance('locations')/countrys/country[count(zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id = instance('commcaresession')/session/user/data/commcare_location_id]) > 0]/name

But I get the following error when I try to deploy:

Build Failed!

Validation Error: can't get triggers for relative references in form Danger signs in module "ALMANACH"

Is my syntax wrong?

Thanks,

Alex

Cory Zue

unread,
Nov 2, 2015, 2:58:40 AM11/2/15
to commcar...@googlegroups.com
Hey Alex,

This looks like it could be a bug on our side. I'm going to make a ticket for the issue and someone on our team will follow up soon.

thanks,
Cory
Message has been deleted

Alexandre Vanobberghen

unread,
Nov 24, 2015, 9:41:57 AM11/24/15
to commcare-users
Hi Cory,

The above issue was fixed by Sheel, thanks for this!

However, I still face an issue when trying to retrieve the mobile workers location from the organisation hierarchy: (refering to https://wiki.commcarehq.org/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications)

Having the hierarchy Country / Zone / Province / District / Health Facility, I assigned my "test" mobile worker to a health facility.
I can get the location ID using: instance('commcaresession')/session/user/data/commcare_location_id.
However, the following command fails:  instance('locations')/countrys/country/zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id = instance('commcaresession')/session/user/data/commcare_location_id]/name
I get the following error when opening the form:

"Error occured - The problem was located in calculate expression for /data/variables/userLocationName
XPath evaluation: type mismatch
instance('locations')/countrys/country/zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id = instance('commcaresession')/session/user/data/commcare_location_id]/name was not found"

Not sure what the issue is. Is the issur the command's syntax? Or the actual location ID?
Any idea?

Thanks,

Alex

Sheel Shah

unread,
Nov 24, 2015, 9:45:08 AM11/24/15
to commcar...@googlegroups.com
Hi Alex,

On your Organization levels page, can you click on the Advanced checkbox and review the organization level codes you have.  These should match what you're using in your syntax above. 

Does the actual location ID calculate correctly?

Thanks,
Sheel




--
Sheel Shah
Project Manager | Dimagi
m: +1.781.428.5419 | skype: sheel_shah


Alexandre Vanobberghen

unread,
Nov 24, 2015, 11:23:46 AM11/24/15
to commcare-users
Hi Sheel,

Thanks, this solved it.
I was in fact referring to the organisation level rather than the type code. So I replaced "health_facility" by "health-facility" and it did the trick.

It could be useful to add a line on the help page to say that the type code should be used in the syntax? (https://wiki.commcarehq.org/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications)

Thanks for your help!

Alex



Sheel Shah

unread,
Nov 24, 2015, 2:10:37 PM11/24/15
to commcar...@googlegroups.com
Thanks Alex! I've updated that help page. 

--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages