A multi-level insert operation (or chained insert operation) allows insert operations for multiple mobile business objects that have a defined relationship during one synchronization, provided the insert operations have parameters that match the MBO relationship.
Some business processes require multiple related enterprise information system (EIS) operations, for example, creating a sales order with line items. The parent/child relationship is often represented by primary key(PK) / foreign key(FK) attributes in the parent and child MBOs. When you construct these types of MBOs in an offline client application, the PK/FK key values are transitory. When EIS operations are called to create real data, the EIS systems generate the actual key values, and the primary key of the parent is copied across to the related child MBO creation operations. These types of operations are known as "chained insert" or "multilevel insert".
When defining multi-level insert operations, ensure the child MBO is non-syncable, unless you are sure that the child MBO will be synced either independently, or through the parent MBO. If not, when the device application designed from these MBOs runs, the child MBOs display on the "Synchronize" screen. If the device application user invokes "Synchronize" on any of the child MBOs, a "Missing-Sync-Param" exception occurs.
The insert operation for the parent MBO must return a single row, and among the columns it must contain the primary key values. The column labels must match the attribute names of the parent MBO.
CREATE TABLE parent(pk int autoincrement primary key, p1 varchar(30),...) CREATE TABLE child(fk int references parent.pk, ...)
INSERT INTO parent(p1, ...) VALUES(?, ...); SELECT * FROM parent WHERE pk = @@IDENTITY;
This batch query inserts the new parent row and then returns a single row containing the newly generated primary key value.
You must understand the key generation mechanism used by the EIS application from which you are developing, and be able to determine how to retrieve the newly generated keys during the insert operation (frequently, this logic is wrapped in a stored procedure).
This same technique applies to Web service, SAP, or other EIS systems, though the insert operation definitions differ.
The single row that is returned must contain all of the columns referenced in the relationship from the parent MBO to the child MBO, and the labels of the columns must match the from attribute names of the parent MBO.
All columns from the inserted row are not strictly required. For example, not all columns are selected or required for a drag-and-drop database operation.
If the child has multiple foreign key attributes pointing to the parent, the relationship should list all relevant parent-to-child attributes. As long as the row returned from the parent insert contains all those columns, the child insert should work; all the foreign key fields are populated from the parent insert result set.