Missing App ID when editing a case

We’ve come across an interesting issue using the API to pull case management records. New records contain the App ID, but when a record is edited, a new record is inserted but has a null value for the App ID which causes an issue with our API call which filters data by the App ID.
Any suggestions on how to deal with this would be appreciated. I imagine it’s a defect?
@Calvin @MikeLu

Just to add, reading here: https://confluence.dimagi.com/display/commcarepublic/Data+Cleaning%3A+Clean+Case+Data
App ID is part of the metadata which obviously isn’t user editable.

Hi Ed

Can you be a bit more specific. Are you editing forms or cases? Cases don’t generally have an app_id associated with them. I tried out editing a form but the app_id field was still correct after using the ‘data cleaning’ feature.

We are updating a case using the clean case function in commcareHQ. I see that it creates a new form instance that is associated to the case and has the type “System”, but within that form does not have an app_id. The initial capture for the case data is done through the mobile app and that form has an app_id linked to it.

Is there a way to only pull system type forms using the form API or pulling where the app_id = null?

Hi Simon, within the Commcare documentation it states that metadata does not change. See the highlighted text in picture below:

and here is the page link:
https://confluence.dimagi.com/display/commcarepublic/Data+Cleaning%3A+Clean+Case+Data

If you follow this link below you will see that the app_id is part of the meta data.
https://confluence.dimagi.com/display/commcarepublic/Metadata+Glossary

This is specific to cases only, when a case is edited in Commcare HQ it creates a new form for that case. This updated form app_id is then set to NULL. Which is a problem with the API because when we pull the form data from the API for a specific app_id it doesnt pull through the updates that were made in Commmcare HQ.

Was it intended that the app_id is NULL when updating through Commcare HQ as it is part of the meta data?

I see what you are saying now.

When you edit a case the changes are applied to the case by submitting a new form but since the data cleaning form is dynamic and not part of any Application it can’t have an app ID. Cases can also be used in multiple Applications so there’s no clear way to say that a particular case belongs to any specific app.

The metadata being referred to on the wiki is case metadata (since you are editing a case). If you were editing a form you would see that the app_id field of the form does stay the same.

Is there a way to only pull system type forms using the form API or pulling where the app_id = null?

You can filter by XMLNS: xmlns="http://commcarehq.org/case/edit"

Hi Simon, thank you for the response. I can understand why it was setup in that way.
We were able to find a solution to the problem, what we did is instead of trying to clean the actual case, which when doing so creates a whole new form with a NULL app_id, we went to the Form History tab and cleaned the actual form. In this way updating the form doesn’t create a new form but just edits the initial one created by the app, so it keeps the app_id. This solved our problem.