Accessing selected Case ID in Case List from sub menu with Advanced Modules

Hi,

I have the following menu structure:

  • Standard Module 1 (case_type_1)
    • Advanced Module 2 (case_type_2)

One of the properties of case_type_2 is an ID of case_type_1. There is no parent/child relationship between these case types.

I can't find the xpath expression that would allow me to filter the case list in Module 2 based on the case_id of the case selected in Module 1.

Could you help me figure out what would be the correct xpath, if this is possible?

Thanks,

#IT4LIFE

Hi Guillaume,

I think that the expression you want is

property_for_case_1_id = instance('commcaresession')/session/data/case_id

which I believe should filter the list of case_type_2 cases based on the selection from the first case list.

-Clayton

Hi Clayton,

Thanks for your answer. I had tried this before and it didn't work. I was really puzzled since I had seen that answer in many places in the forum and on the wiki. It turns out it was a copy/paste issue with the single quotes... My zen was tested again.

Cheers,

Ah, right, sorry. Discourse annoyingly automatically replaces the ASCII single quote with unicode fancy quotes, which wreaks havoc on copying and pasting some expressions.

I found a setting in discourse that claims to disable this behavior so that we won't have similar issues. Added some tests below

'test'
'
"
instance('casedb')/casedb/case[testvalue = "one"]

2 Likes

Hello there,
I have almost same issue here,
Menu and submenu whth no parent child relation, but I don't have case id value in the submenu instead, I have other case property which is Beneficiary_ID, which should be selected from the parent menu, accordingly, we should filter the submenu case list

Any support is pretty much appreciated

Hi Raneem

Clayton's advice is spot on.

you just need to consider which fields need to be filtered by which fields.

depending on which case list you are on, you can reference the "current case" properties by just using the property name in caselist filters.

the caselist filters run row by row, and assume that you are referring to the row currently being evaluated in your case list.

in Clayton's example
if(instance('locations')/locations/location[@id =

he is in the caselist filter for layer 2 if I understand correctly - it is generally a bit confusing when you're in that part of the system.
property_for_case_1_id is stored in the second layer's case.
instance('commcaresession')/session/data/case_id refers to the case that was selected in the parent menu.

so that code is saying "while I am in the second menu's case list, I want to check that the property from the second menu's case currently being avaluated has the same value as the case id of the case that I have selected on menu 1."

mouthful I know!

hope this helps

Many thanks for your reply, Mazen,
I did exactly same, but getting the error "Logic references instance(commcaresession)/session/data/Beneficiary_ID which is not a valid question or value."

the filter I added was like: Beneficiary_ID = instance('commcaresession')/session/data/Beneficiary_ID
where the Beneficiary_ID is the case property both in the case of the parent and submenu

Any advice?

your reference is just incorrect

where you put this filter matters in how you can access the information you wish to filter by.

for case_id is not the same as beneficiary ID. case id is a standard field in context that can always be referred to. beneficiary ID is something YOU added.

I suggest looking at the data preview to see what information is in the form, and maybe start here for more information
https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143958248/CommCare+Session+Instance

data preview

do not worry. it takes most of us multiple tries and sometimes days to get the syntax correct for these things.