Custom location data giving error (which is not a valid question or value)

Hi there,

I am facing an issue where I am following the instructions set out on the below page to access custom location data.
https://help.commcarehq.org/pages/viewpage.action?pageId=38276915#ReferencingtheLocation/OrganizationHierarchyinApplications-Accessingthelocationadditionalinformation(LocationFields)

This is what happens when I load the survey:

error more or less = (which is not a valid question or value)

this is what my calculation field value looks like:
instance(‘locations-1’)/locations/location[@id = #form/QListMain/site]/location_data/testid

However if I reference site_code using this calculation I get back the expected value and it seems to work (Notice the custom id label)
instance(‘locations-1’)/locations/location[@id = #form/QListMain/site]/site_code

This is my custom location field

This is what my little survey looks like:

@Clayton_Sims I have a feeling you might have an answer for me here?

Hi,

My guess is that there’s there’s an issue with the location_data part of your query.

It would probably be really helpful to use the Evaluate XPath expression tester from this tool:

https://confluence.dimagi.com/display/commcarepublic/Web+Apps+Data+Preview

and do a direct query for

instance(‘locations-1’)/

to see what is inside of the data model and whether it matches what you expect within the location_data block.

-Clayton

I’ve actually had this “-1” pop up on its own whenever i tried this

any idea where it’s coming from?

Mazz

Hi @Clayton_Sims,

I can see that the location data is there, and the custom field testid.
So I came to the conclusion that the code:
instance(‘locations-1’)/locations/location[@id = #form/QListMain/site]/location_data/testid
is actually correct then.

I randomly started fiddling and then came across setting a location for the mobile user.
I noticed that it wasnt set to anything and so I set it, and then logged back in.
As soon as I did that. It worked.
So if the mobile user has no location set this is the error that is thrown.
image

This is the result I got back by running the xpath evaluation: instance(‘locations-1’)/locations/location


Cape Town Hospice
<site_code>cape_town_hospice</site_code>
<external_id/>


<location_type>Site</location_type>
<supply_point_id/>
<location_data>
CT1
</location_data>


Eastern Cape
<site_code>eastern_cape</site_code>
<external_id/>


<location_type>District</location_type>
<supply_point_id/>
<location_data>

</location_data>


East London Hospice
<site_code>east_london_hospice</site_code>
<external_id/>


<location_type>Site</location_type>
<supply_point_id/>
<location_data>
EL1
</location_data>


South Africa
<site_code>south_africa</site_code>
<external_id/>