Hoping someone can help me out here I cant seem to get the Model Iteration to work correctly in a repeat group when looping through the casedb.
As an example I have a simple app with 2 cases: "mother" and "child"
"child" is a child case of "mother"
Basically what I want to do is use a repeat group to loop through the "child" cases for that "mother" in the followup form for the "mother". The followup form basically acting as a edit form for the "mother" case properties and "child" case properties. I know this is not standard operation/practice of editing child cases. My thinking was to use save-to-case in the repeat group to edit the "child" case properties.
Hope that makes sense will give some more detail below but first the repeat group error:
my followup form
the repeat group Model Iteration ID Query:
instance('casedb')/casedb/case[@case_type = 'child'][index/parent = #form/mother_details/mother_case_id]/@case_id
The app is very simple, only case properties are:
"mother" - (mothers_name = case_name) (age)
"child" - (child_name = case_name) (age_in_months)
The child cases are created from the mothers registration form.
Any help would be greatly appreciated!
I've never used model iterations before and quite frankly I am not exactly sure what the use case is.
I have loaded cases in repeats before. I did brute-force my way through it though.
I counted the cases that fit the criteria and used that as a repeat count
I queried the Case DB object to grab the list of case id's
used those case id's to grab the rest of the case details inside the repeat, making sure i'm pointing at the correct case ID by using the parent and position functions inside the repeat
it made a lot of calls to the casedb object as well as look up tables. so it was a slow form when I had it. but it DID work.
That should work as you have it. What are the expressions used in the repeat group questions? I think these ones should be:
Hi @Mazz and @Simon_Kelly,
Thank you so much for the responses guys, so encouraging to see how active the forum is.
@Mazz thats exactly what I ended up doing, got it working like that, but I would love to have the knowledge to get the Model Iteration working, wondering if its maybe a more efficient way of doing it.
@Simon_Kelly I eventually gave up cause I couldnt get it to work. Would be great though if we could get this to work. With the modal iteration when it iterates through each child case is it bringing back all the case properties for each child or do you still have to query the Case DB making use of the item_id for each case property? Hopefully that makes sense?
What you have for item_id and item_index is exactly what I have.
see pics below:
Still gives the same error, just had a thought in the past I have had weird errors like this because I copied the questions from another form. Im going to try recreate the form questions from scratch and see what happens. Will come back and let you know.
Still gives the same error
Odd. I created a test form like this and it worked fine.
With the modal iteration when it iterates through each child case is it bringing back all the case properties for each child or do you still have to query the Case DB making use of the item_id for each case property?
Model iteration still only gives you the case IDs (or whatever property you select from the case in your query - but case ID generally makes the most sense). So you still need to use the Case DB to access the other case properties:
instance('casedb')/casedb/case[@case_id = current()/../@id]/case_name
Thanks so much @Simon_Kelly there must have been something fuddy going on with my questions because, I copied them from another form. I recreated the repeat group and the questions beneath it and it worked like a bomb! Have a feeling it was the repeat question in particular as it was previously setup to repeat on a counter, maybe something lingered that shouldnt have when I updated it.
Thank you for this! So either way its more or less the same, but really great that it works now. Thank you!