<< Click to Display Table of Contents >> Navigation: Collect > Collect Enterprise > Template Designer Page > Parent-Child Relationships in Collect Templates |
Parent-child relationships are created when a subform is created for a form. The form is the parent to the subform, also known as the child form.
Collect template records, such as a form, are denoted by unique identification numbers known as the #id. A child form contains — in addition to its own #id — #parent_#id identification numbers that are auto-generated by Collect.
Both the parent form and the child form will each have a unique #id value. To connect the parent form to the child form, the child forms #parent_#id value must match the parent forms #id value. One of the benefits of setting up subforms as a child form to a parent form in the Template Designer is this connection is automatically configured, hence you are able to see the defined child form records under a given parent form in Collect Mobile as seen below:
Note: Parent forms do not have a #parent_#id field to populate. |
---|
The parent-child relationship defined between a form and its subform spans across many steps in the EQuIS Collect workflow, as outlined in the sections below.
Auto-generated #ids can be overwritten during pre-population.To pre-populate a child form record, the parent record needs to be pre-populated first, otherwise the child form record is orphaned in Collect Mobile. To do so, pre-populate the parent record and use a value from the report table that is unique for each record being pre-populated to populate the #id field value. For example, a sample record is to be pre-populated, the sampleid is a unique value appropriate for populating the #id value.
Once the parents form #id value is configured, in the pre-population of the child form, set the #parent_#id to the same value as the parent form’s #id value.
Notes: •The unique value chosen to pre-populate the parent form’s #id value should be present in both report tables used to pre-populate the child and parent form. •A common #id or #parent_#id value used during pre-population is FACILITY_ID. It is highly recommend any time a FACILITY_ID is used as the source for the #id or #parent_#id in the pre-population mappings, to use the ADD function to put the value in its own order of magnitude.
This is because, in Collect when a form/subform record is created Collect creates a #id associated with it. If the FACILITY_ID is ever 1, then the #id or #parent _id of the pre-populated form will be 1, but the the ID of 1 could already be claimed by a form record created prior to the pre-populated record and therefore could break the pre-populated parent/child form relationship.
The best practice is to avoid using low numerals as FACILITY_IDs or SAMPLE_IDs when populating #id or #parent_#id. To avoid this, instead of having #id value = INTEGER([facility_id]) it should be ADD([facility_id,100000]) to create a large ID that is less likely to be consumed already in the data form. After the #id is changed, all subforms associated with the form will need their #parent_#id values changed to ADD([facility_id,100000]) as well. |
---|
The #id and the #parent_#id fields discussed in this article are available for selection in the Formula Builder under Section Fields:
To populate a child form field with a value from a field in the parent form, add the following prefix to the field name of the field in the parent form, #parent_[ParentFieldName]
Example:
Template Setup:
•Parent Form: FieldA
oChild Form: FieldB
Scenario: You want the value of FieldA from the parent form to populate FieldB in the child form by default.
Solution: You can call upon FieldA to populate FieldB's Default attribute using the following field:
[#parent_FieldA]
Filtering out child records that belong to a given parent record can be useful when creating a set of data records for a formula especially in the FormFilter attribute for fields such as the Table Form or Form Lookup fields using the FILTER function.
Scenario A: To filter all associated child form records of a parent form, while in the parent form records, use the following formula in the condition parameter of the FILTER function:
EQ([#id],[ChildFormName.#parent_#id])
Where ChildFormName is the name of the child form.
Example:
FILTER(EQ([#id],[ChildFormName.#parent_#id],[ChildFormName.Field])
Scenario B: To filter all the child form records belonging to the same parent form, while in the child form, use the following formula in the condition parameter of the FILTER function:
EQ([#parent_#id],[ChildFormName.#parent_#id])
Where ChildFormName is the name of the child form.
Example:
FILTER(EQ([#parent_#id],[ChildFormName.#parent_#id]),[ChildFormName.Field])
Copyright © 2024 EarthSoft, Inc. • Modified: 23 Feb 2024