0

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.

1

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.

1
  • It worked with the following expression: instance('casedb')/casedb/case[@case_type = 'commcare-user']/y_value. What is the reason for including the [hq_user_id = instance('commcaresession')/session/context/userid ]?
    – Ali F
    Apr 21 '17 at 11:10
0

Your question references both Custom User Data as well as the User Case, can you clarify which of the two you are attempting to use in the app?

The user case is an object which can be read or written to from forms in a CommCare app, while Custom User Data must be written on the user object on the server and is read-only on the device.

Also: You will need to clarify the context in which you are trying to reference this information. The syntax for how data is queried in CommCare is not global, so the manner in which you make references like this will depend on a few other factors.

1
  • edited to clarify that I am talking about referencing the user case, not custom user data, and the context in which it is being referenced.
    – Ali F
    Apr 20 '17 at 7:59
0

For referencing user case properties in the case list or detail, change cases from Daniel's expression to casedb:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.