Case name referencing

Hi Evereyone,

I am trying to reference a case property in a follow up form but for some reason the question pulls the case id rather than the case name, how can i fix please?

image

I need the Group name to show up and not the ID, the same way the Department and Commune are showing up. The group detail is a separate case list though

The field i need to reference is this:

but rather its referencing the Case ID field in the form

Hi Jay, what expression are you using which evaluates to the case ID? Regardless, given the ID, you should be able to use this expression to obtain the case name:

instance('casedb')/casedb/case[@case_id = ID_EXPRESSION]/case_name

Hi @Ethan_Soergel,

I actually wasn’t using any expression since i have the group name saved as a case property so i only referened it in the form but then it’s picking up the case ID.

The current expression i am working on is this:

instance(‘casedb’)/casedb/case[@case_type = ‘benibiz_training_group_new’][Case_Id = #form/name_and_date_group/group]

But haven’t gotten it right yet.

Should it be:

instance(‘casedb’)/casedb/case[@case_type = ‘benibiz_training_group_new’][Case_Id = #form/name_and_date_group/group_name]

@Ethan_Soergel

Should the expression be placed within my hidden field?

I believe this should be the expression:

instance('casedb')/casedb/case[@case_type = 'benibiz_training_group_new'][@case_id = #form/name_and_date_group/group_name]

That is, I changed Case_Id to @case_id. Your screenshot above includes curly quotes and , which I replaced with simple quotes '. That can sometimes happen if you copy/pasted from a rich text editor like Word or email. The “Lexical error” in your screenshot refers to that issue.

Hi Ethan,

Can you also tell me how i can pull the actual name of the group in the report? Right now in the survey the group name is being properly referenced but when i pull the data into excel or power BI, its the case id thats still showing up.

Please help.

The syntax keeps reverting

It looks like that case ID is being saved as the answer to that lookup table question, is that correct? You need a hidden value with the calculate set to:

instance('casedb')/casedb/case[@case_id = ID_EXPRESSION]/case_name

But instead of ID_EXPRESSION, drag and drop the lookup table question there.

Hi @Ethan_Soergel,

Thanks so much, this works well. I have also saved it as a case property and pulling that property in subsequent follow up forms so it makes sense to the end users of the data.

Can you also help me with another issue, i have submitted a ticket for it earlier today. It has to do with archiving forms. I archived all the forms in my surveys so that we could test the surveys with fresh data. The archived forms do not show up in a regular form data export but they still show up when i do an excel dashboard report.

Kindly assist.

That’s good to hear. One word of caution about saving the name as a case property. You’re saving the name at the time the form is filled out - it’s not a reference to the group case’s name. This means if the name is later changed, it won’t be updated on this case. The alternative is to save the group case ID instead, and look up the name every time. Depends on what’s more appropriate for your use-case.

I don’t have a good answer to your other question, sorry. Archiving forms is intended to hide them from reports and exports, not sure whether there’s a straightforward way around that.

Yes i am still pulling the case ids alongside the case names as well.

Thanks so much @Ethan_Soergel

Hello @Ethan_Soergel,

Can you please assist again with this same issue? For some reason, its not working when i try to implement this in another application.

I need to use a multi select to enter all farmers present at a training. If i set the form as a follow up then the user is forced to pick a farmer before entering the form so i decided to set it up as a registration form but i placed an open case condition on it. Any alternative solutions to this method are highly welcome please

image

When i download the report in excel, the question “select which farmers are present” produces the case ids while the case_name_label does not pull the actual name

I need the column referncing the name

current syntax inside my case_name_label hidden field is

instance(‘casedb’)/casedb/case[@case_id = #form/farmers_present]/case_name

Hello again Jay

You’re almost there. it’s the same thing as i was explaining to you on the other post.

a multi-select will not return a single value. it’ll return a set of caseID’s separated by spaces. so, the “=” operator will always not find the exact caseID. it’ll always have some other caseID’s with it.

so what you want to do is
join(instance(‘casedb’)/casedb/case[selected( #form/farmers_present]/case_name,@case_id)]/case_name,",")

this will return a string of case_names, separated by commas, for the cases selected in farmers_present.

then you save that into a case property that will be available in a case download.

P.S: The correct forum for this type of inquiries is “users” section. The developers section is designed for those who have in-house implementations of CommCare and/or building other software that works WITH commcare. the users space is designed for questions and discussions the community has about building and using CommCare apps and exports.

correction

join(instance(‘casedb’)/casedb/case[selected( #form/farmers_present,@case_id)]/case_name,","))

Hi Mazz,

Thanks so much for the response but i am still getting errors here. been trying to tweak the syntax but its still not working.

Been replacing those curly quotes but the system still complains

I think that last parenthesis is superfluous, actually. You may also want to play with the separator, I changed it to “comma space”:

join(instance('casedb')/casedb/case[selected(#form/farmers_present, @case_id)]/case_name, ", ")

Hi @Ethan_Soergel,

Unfortunately, the syntax still doesn’t work. Please see error below

Hi Jay

I think i was the one that made the error

the first argument in the “Join()” function should be a single value to join with the rest.

so in our case, it should be
join(", ",instance(‘casedb’)/casedb/case[selected(#form/farmers_present, @case_id)]/case_name)

I think that might solve this error

Mazz

it explains it here

https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-join

Hi @Mazz, Thanks so much . it seems to be working well now. I was just about to ask for a link that explains the syntax.