Does it possible for multiple sub forms sharing variables?

Hi everyone,
I have created master form that linked with 5 sub-form. All subform is linked to the master form using the same value ‘call_id’.
Below is the sample structure:
A. Master Activity form

  1. Sub Form - Tank Measurement:
    fields: call_id, temperature, water_level, (other fields)
  2. Sub Form - Room Measurement:
    fields: call_id, temperature, water_level, (other fields)

The field that has the same name, might have the same value, so in order to make it faster for user when they are filling the forms, I want to make the value from the subform 1 become the default value for fields in the subform 2.

I have tried to link the forms using linked_forms. So, master activity form linked to subform 1 and 2, and subform 1 linked to subform 2. But, the data from subform 1 only shown on subform 2, when the subform 2 is opened via the subform 1.

Any help will be appreciated

Hi @aliahadss24! Are the sub-forms different data about the same observation? If so you can use the same table_id and different form_id and that will solve this. If they are different observations (there are multiple tanks per room or multiple rooms per tank) you are going to have to use async_assign to pull the data from one form into another. See directions here: Using ODK-X XLSX Converter — ODK-X Docs in terms of customizing prompts section.

1 Like

Thanks for the hint. I tried using the async_assign but when I test it on my phone, the next button is no longer working out and the survey is unable to go to the question. Turns out its because the handle bars path on the customPrompt.js is not correctly set. I think it would be nice to have that thing pointed out on the docs.

Now its all now working perfectly

2 Likes

Hi @aliahadss24

Thanks for pointing that out. I have filed a pull request to update the documentation.
Tracked at Include templatePath update in async_assign doc by linl33 · Pull Request #50 · odk-x/docs · GitHub

2 Likes

Btw, I have a follow up question, one form might do multiple async_assign to different field from the same form. On queries sheet, I have to create multiple lines of linked table that linked to same table but refer to different field. Is there a more efficient way to do this? Thanks in advance :slight_smile:

If you want different fieldNames, alas, you do need different queries, since that is where you specify the fieldName. Hopefully just copy-paste-update easily enough!

1 Like