Tips & Tricks - Parameters - Save parent data record with child data records
This article shows how any number of subordinate data records can be created and saved at the same time as a new data record. Here you will find a ZIP file with a sample app that you can import into a portal as usual.
Example application in the browser
If the sample application is open in the browser, a new parent data record can be created on the "Overview" start page by clicking on "New".
In the following tooltip, data for the parent record can now be entered in the edit field. Click on "Add child data record" to display another input field in which data can be entered. By clicking on "Add child data record", any number of input fields can be displayed and any number of child data records can be created. Click on "OK" to save all child data records and the associated parent data record. The 1:n relationship between the parent and child records is created automatically.
On the overview page, the child records can be displayed by clicking on the magnifying glass button to the left of the ID.
Structure of the example application
To create a parent data record together with any number of child data records, the requirements described below must be met.
Primary key of the parent data group with data type "GUID"
The primary key of the parent data group must have the data type "GUID".
Parameters of the edit page
The setting "Parameter is only used for existing data records" must be deactivated for the STRID parameter on the parent data record input page.
The newly created fallback value "uniqueGuid" is required for the "STRID" parameter, which is used to generate a new GUID.
Additional binding in the WriteContainer of the parent data group
A binding must be set for the data record in the write container of the parent data record. To do this, select "Parameter" as the source, "STRID" as the parameter and the primary key as the target.
Additional binding for the "OK" button
In the actions of the "OK" button, which should save the parent data record together with all child data records, the write container must be added to the freely designed table.
Configure the free layout table
The input page from the subordinate data group must be included in the free-form table.
Button for creating the child records
In the actions of the button that inserts child data records in the freely designed table, the action type "Add data record" must be selected with the control "Freely designed table" and the parameter "STRID".
Summary
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 input page of the free table using the "Add child data record" button. The dependency requires that the foreign key is present accordingly.