CommCare – Syntax for Referencing User Case Properties

commcare

I created a user case property in my app, and now I'd like to reference the value of that user case property in a concat function. It is being referenced in a Report Module to indicate at which y_value I want my 'Y Label' to appear. The syntax for y-labels is: '{ "y_value": "Y Label" }'

Because my y_value is dependent on the user, I have created a y_value user case property to reference in the above expression. In order to do so, I will need to concatenate the pieces of the above string with an xpath expression:

concat('{ "', instance('commcaresession')/session/user/data/y_value, '": "Y Label" }')

But that is giving me an xpath error on mobile (saying it is not a valid question or value). Is this the correct syntax to reference a user case property in this context?

instance('commcaresession')/session/user/data/y_value

I got it from the custom user data wiki because the user case wiki doesn't have any info about syntax, but that expression is throwing an xpath error on mobile. Wondering if user case uses different syntax.

Best Answer

The form builder references the user case like this (broken onto multiple lines for readability):

instance('casedb')/casedb/case[@case_type = 'commcare-user'][
    hq_user_id = instance('commcaresession')/session/context/userid
]/y_value

If you have the "Easy-reference user properties in the form builder" feature flag enabled you can reference the user properties (aka, the user case) with syntax like #user/y_value from within the form builder.