Tips & Tricks - Parameters - Save parent record with child records
This article shows how any number of child records
can be created and saved simultaneously with a new record.
You can find a ZIP file with our example application here
. You can import
this into your portal as usual.
Example application in the browser
Once the example application is opened in the browser, a new parent record can be created on the "Overview" home page by clicking on "New".
In the following tooltip, data for the parent record can now be entered in the edit field.
Clicking on "Add child record" displays another edit field where data can be entered.
By clicking on "Add child record" again, any number of edit fields can be displayed and therefore any number of child records can be created.
Clicking on "OK" saves all child records and also the corresponding parent record.
The 1:n relationship between the parent and child records is created automatically.
The overview page now displays the GUID (primary key of the parent record) and the entered data.
Clicking on the magnifying glass button to the left of the GUID opens a tooltip that also displays the child records that have been entered.
Structure of the example application
To create a parent record together with any number of child records, please perform the steps described below.
1. Primary key of the parent data group with "GUID" data type
The primary key
of the parent data group must have "GUID" as the data type
This data type can be selected when you create a new data group
2. Parameters of the edit page
The setting "Parameter is only used for existing data records"
must be disabled for the STRID parameter of the parent record edit page.
The new fallback value
"uniqueGuid" created for the "STRID" parameter is required to generate a new GUID.
3. Additional binding in the WriteContainer of the parent data group
for the record must be set for the WriteContainer
of the parent record.
To do this, "Parameter" is selected as the source, "STRID" as the parameter, and the primary key as the target.
4. Additional binding in the WriteContainer of the parent data group
In the actions
of the "OK" button, which is going to save the parent record together with all the child records, the WriteContainer of the free layout table must be added
5. Configure the free layout table
In the free layout table
, the edit page from the child data group must be included.
6. Button for creating the child records
In the actions of the button that adds child records to the free layout table, the "Add record" action type must be selected with the "Free layout table" control and the "STRID" parameter.
What is special about this example is the fact that the parent data group record is not created until the child records are created.
In this case, the unique ID must be generated for the parent record.
This is achieved with the fallback value "uniqueGuid", which automatically generates a new GUID.
This value must then be transferred to the edit page of the free layout table via the "Add child record" button.
The dependency requires that the foreign key is present accordingly.