When a
record needs to be created, updated or deleted in a form data source based on
the joined form data source, we can achieve this using ChangeGroupMode and OptionalRecordMode
properties on form and form data source respectively.
Problem
Consider two
tables TaskTable and CriticalTask, such that the CriticalTask table contains
the foreign key relation with TaskTable. We need to create record in CriticalTask
table if the checkbox is marked check.
Solution
Follow the
steps below to create/delete a record based on joined table.
Step#1 Create tables MY_TaskTable and
MY_CriticalTask with a Normal relation between two tables.
Step#3 Set the property Data Source Change Group Mode to ImplicitInnerOuter to use a change group for the tables
in the form data source.
A change
group is a set of joined tables in a form data source. The change group
uses UnitOfWork framework to implement database transaction, such that if create,
update or delete fails for any of the tables in change group, the change is
rolled back for all the tables in the group. For further information
regarding Change Group Mode property, see Change
Group and Optional Record Modes.
Step#4 On form data source for
MY_CriticalTask, the Link Type must
be set to OuterJoin to use optional
record mode. Set the property Optional
Record Mode to ExlicitCreate.
Setting the
Optional Record Mode to ExpliciteCreate, we use a check box control to explicitly
specify whether to create or delete the joined record. If the check box is
selected, the record is always created. If the check box is cleared, the record
is always deleted. For further information regarding Optional
Record Mode property, see Change
Group and Optional Record Modes.
Step#5 Add a checkbox on form and set
the Data Source to MY_CriticalTask
and Optional Record Control to Yes.
This check box will work as a command to create a record in table
MY_CriticalTask for the respective MY_TaskTable record.
Execution
It can be now observed on form that when the check box for
Critical task is marked checked, a record is added to the MY_CriticalTask table
for the selected MY_TaskTable record. Whereas, on unchecking the checkbox, the record
is deleted from the MY_CriticalTask table for the selected MY_TaskTable record.