Can "_id" field be used in Dynamic Data Attachments?

Hello!

I’m using the automatic “_id” field in a Parent form in order to print barcode labels in order to identify different material batches.
I would like to know if its possible to use that _id value in Dynamic Data Attachments as the required “serial number / identifier” input in the child form so the rest of the data from the parent project can be retrieved.

If not, is there any way to create a calculate field in the parent project that “mimics” the _id field so it can be used in Dynamic Data Attachments?

Thanks

@jventayol, _id is a system generated variable hence you cannot use it with a form.

Hello @Kal_Lam,

Thanks for your quick answer
Is there any way to create a calculate field in the parent project that “mimics” the _id field so this new field can be used in Dynamic Data Attachments?

Regards

I must say no not at the moment because you are trying to use the _id field which is a system-generated field. You can only control the variables which you have created. Please also be informed that the DDA feature works in the same way the pull-data function works. The only difference between the two is that the pull-data function pulls data from the CSV file while the DDA pulls data from an existing project that is deployed in the KoboToolbox server.

As @Kal_Lam correctly states, presently the _id field is a Kobo backend assigned field, and one which - since it isnt part of the actual ‘parent’ form definition itself - isn’t included in the shared xml-external data file.

It conceivably could be included, but that would be a new feature change. Please feel to propose something in the Suggestion Box, explaining what you want and why you think it’ll be useful to others. :slightly_smiling_face:

That said, you might be able to accomplish something similar or equivalent today, albeit without the actual _id field per se. All form submission already come with an associated UUID, which uniquely identify that submission. Parent form submissions included… Typically the submission UUID iis hidden from the user, as metadata, but it is still part of the submission XML, so in practice you can [sometimes] access this UUID from within your form. And by basically duplicating this UUID into one of your own form fields (read-only of course, since you dont want the user changing it) then your own uuid copy will appear in the parent form as a shareable field to your child forms. So you could possibly achieve what you desire using this uuid instead of the _id.

Have a play around with these parent & child forms, and see if it might accomplish what you are thinking. Note, you need to add a name = 'data' to your parent form settings to fix the XML root instance identifier (which is otherwise a random string in Kobo) so you can correctly reference the instanceID element in the metadata XML calculation; ie /data/meta/instanceID. This instanceID element contains the generated UUID for your submission; it is always prefixed with ‘uuid:…’, hence my substring-after() to strip it off.


Parent.xlsx (18.3 KB)


Child.xlsx (15.5 KB)

Once you have this UUID in your Child form you can possibly use it as an equivalent unique identifier for the Parent.

Caveat

:warning: I say sometimes above because there appears to be an issue in Enketo where the calculation copying the metadata instanceID isnt firing (!?), so parent form submissions submitted from Enketo end up with an empty uuid field. :slightly_frowning_face: However, when submitted from KoboCollect, the uuid field is correctly populated with the instanceID.

The Parent form and Child form have both been tested and work fine on KoboCollect. The Child form has been tested and works fine on both KoboCollect and Enketo. The Parent form does not work correctly on Enketo (as described above).

I’m investigating why Enketo doesn’t (it may be a bug to fix…)

2 Likes

Hello @Xiphware,

Thank you very much for your detailed and illustrative reply. I found a workaround creating a “custom” id based on the enumerator inputs (concatenating basically) plus the current date.
Additionally I just discovered the following article after I posted this thread:

So, in the end, an additional calculation question is the easiest way to identifify the submissions so it can be linked between projects/forms.

Sorry for not checking properly the documentation before posting a support request.

Thanks for your help @Kal_Lam and @Xiphware !

2 Likes