Reopen an ODK collect's instance from external app

We've been able to use a react-native project as the external application that fills out multiple fields of an ODK form.

In the body::intent I can send the instance's uuid,

org.mycompany.myapp( uuid=/myform/meta/instanceID)

but how could I send the id needed to later open or edit that same instance or is there another way to achieve this?

This is not currently directly possible because the instance id is not saved in the instance database and therefore not available to external applications. What you could do is use the instanceID or some other known value as the instance name and filter a query to the instance provider on the displayName column which uses the instance name.

You could also do something like list all instances in the content provider, showing their display name, and let the user of your app pick one as appropriate.

Can you describe your workflow in more detail?

Hello @LN, Thank you for the support.

I'll start exploring what you are suggesting. Filtering by something like displayName would give me all of the instances of that form right? I feel like I could use one of the parameters of each filled form to filter to a particular instance, but still don't know how.

We are developing an platform for small coffee farmers. The idea here is to support with the organic certification process.

This particular workflow is:

  1. They open ODK collect, and fill out the certification annual form (a very long and complex questionnaire which would be impossible to do without ODK)
  2. In the form, one of the first questions is "Who is the farmer, and what coffee plot are you filling out". This launches our external app sirio, (where I can pass the instanceID to our app). Here they choose the farmer and plot, and our app returns the ids to odk. With these ids, we are able to link all info with our db afterwards.
  3. After they finish the form, they return to our app, where we want to show a status of each farmer and their filled forms (ie Has their form been filled, is it sent, draft, etc). Here is where we want to link the previously filled form which is link our information (using the moment they called on our app) with the current status of instances of ODK collect.

Thanks for those additional details, that helps make what you're trying to achieve a lot more concrete.

The idea is to use the instance provider and to build a filter query. If you look at the docs, you can see an example of filtering on jrFormId.

In your case, I still think your best bet is to use displayName as the filter column because you can easily control its value. This corresponds to instance_name in the form definition. You can set this to /data/meta/instanceID if you want, or to any other unique value (e.g. have a once(uuid()) calculate in your form which you pass back to your app and use as instance name).

This will be particularly useful for your requirement of showing the status of multiple form instances. You can use the same prefix in the instance name for all related form instances and filter based on that. To learn more about querying through a content provider, see Android docs.

Thank you @LN I was able to solve it with your suggestion. :tada:

I'm sending the id when I open the external app:

| type        | name     | label                   | appearance | body::intent                                      |
| ----------- | -------- | ----------------------- | ---------- | ------------------------------------------------- | 
| begin_group | my_group | Fields to populate.     | field-list | org.myorg.myapp(uuid=/myform/meta/instanceID)     |

And I'm also using that same instanceID as the instance name in settings:

| form_title | version                  | form_id | instance_name                                    |
| ---------- | ------------------------ | ------- | ------------------------------------------------ |
| MyForm     | 32 (2024-04-25 18:28:17) | Example | concat( 'My Form name', /myform/meta/instanceID) |

With that I can now identify each instance, and mix the ODK status and info with the data in my app.

1 Like