How to change the parent of a case in a form?


I'd like to change the parent of a case inside a form. I've tried to update the parent_id property with the new parent's @case_id, without success.

What am I missing here?




Anyone, please! :slight_smile:


@guillaume :
I have never tried it myself but one thing you can explore is using save-to-case component to change the parent-id of the case.

Thanks for the tip! This seems to be what we need. We'll check.

Hi Guillaume,
Updating parent_id property with the new parent's @case_id may not work to satisfy your needs. Like Ashish mentioned using save to case question within form builder would be the best route, but it is an open source plug-in and such open source plugins are built by us and our community to address specific use cases are not a part of the generally available CommCare offering, thus not supported by us. I am happy to explore this option if you would like.



We managed to make it work. We struggled a bit to get the ID of the case for which we wanted to change the parent in the form.

Using instance('commcaresession')/session/data/case_id actually returned the case ID of the parent case. Exploring the content of the session/data we realized that we needed to use the following expression: instance('commcaresession')/session/data/case_id_child (child being the case type of the child case).

It's very convenient that the commcaresession has all this data but it's a bit confusing since case_id refers to the parent case when there is parent/child relationship, whereas it refers to the actual case when there is none.

Is there any other way to obtain these IDs in a consistent way in a form?