Filter case list by parent property

This is a followup to Filtering child Case list using Parent property

It seems it is still not possible to refer to parent properties by parent/property_name. The workaround suggested in the thread above (instance(‘casedb’)/casedb/case[@case_id=current()/index/parent]/combine_el =
‘1’) didn’t work for me - attempting to display the case list caused an error on the (Android) device. But I wasn’t attempting a direct comparision to a constant - I was trying to reference the parent property within a contains() function call - could that be the issue?

What’s the current ‘approved’ way of referring to parent (and grandparent) properties in case list filters?

In my current application, I could solve the problem by propagating the case property from from grandparent to parent to child, because the particular piece of information is stable, but I can see scenarios where that wouldn’t work because the information changes over time.

Thanks.

Hi James,

The workaround you listed (to reference the properties directly through the xpath query language) should work for references inside of the case list with the query pattern you’ve provided. The function context shouldn’t matter - the engine fully parses the xpath expressions.

What was the error you were receiving and the full expression you were trying to use?

-Clayton

Another test, just now, showed I mis-remembered what happened when I tried that workaround. My filter expression is:
instance(‘casedb’)/casedb/case[@case_id=current()/index/parent]/isenrolled = ‘1’
What actually happens is that in the form builder, when I go to save the filter expression, I get the message:
Cannot make new version
Case List has invalid filter xpath instance(‘casedb’)/casedb/case[@case_id=current()/index/parent]/isenrolled = ‘1’

I think failure to load the list on the device came when I tried parent/property_name and parent/parent/property_name and grandparent/property_name.

Thanks.

Hi James,

That expression works for me as a case list filter - Question for you, when you paste that expression in, are the single quotation marks the “fancy” style, or the “straight” style?

When I replace your single quotes with directly typed single quotes, the expression saves and builds without issue, ie:

instance(‘casedb’)/casedb/case[@case_id=current()/index/parent]/isenrolled = ‘1’

-Clayton

Well spotted! - I just copied and pasted from the original post, which, as you noticed, but I didn’t, had ‘smart’ (=stupid) quotes.

Last question then: How do I refer to grandparent case properties?

Thanks.

Hi James,

No worries. I think the forum automatically replaces machine quotes with stylized quotes (and appears to strip any fixed-width font styles), which is frustrating. I believe HQ will properly manage double quotes, so it might be safer to use instance(“casedb”) v. instance(‘casedb’), but not sure if the forum will mess those up too…

To answer your second question, once you’ve resolved the reference to the parent case, the same process should work recursively, IE:

Parent Nodeset: instance(“casedb”)/casedb/case[@case_id=current()/index/parent]/

Grandparent reference: instance(“casedb”)/casedb/case[@case_id= $parent_nodeset/index/parent]/grandparent_property

=> instance(“casedb”)/casedb/case[@case_id=
instance(“casedb”)/casedb/case[@case_id=current()/index/parent]/index/parent]/grandparent_property ’

It looks ugly (which is why the form editor tries to provide the syntactic sugar for #parent/property), but under the hood the engine can generally figure out the transformed bulk requests and optimize them fairly effectively .

-Clayton

Yep, the forum mangles double quotes too!

Thanks for your help.

You can prevent the forum from mangling quotes if you mark that text as code in the UI. This can be done by selecting it and clicking the “Preformatted text” button (</>), or by adding backticks on either side of the code. For example:

instance("casedb")

Not sure whether anything similar works if you’re using the forum only over email.

Thanks for the tip (' ").