Here a list of Frequently Asked Questions about the topic Automatic data population associated to transactions:
- In which cases GeneXus automatically sets the transaction Business Component property = True, and in which cases the developer can set it explicitly?
When the developer sets the Use To property of a Transaction = Populate Data, GeneXus automatically sets the transaction Business Component = True, in order to store the data specified in the associated Data Provider in the physical table(s) associated with the transaction. The operation that will be performed -through the Transaction executed as a business component- is an “upsert”; that is to say, an addition will be attempted, but if it fails because a duplicate key is found, an update will be performed.
On the other hand, when the developer sets the Use To property of a transaction to Retrieve Data since no physical tables are created in association with the transaction, the Business Component property remains with its default value (False). The developer can set it to True (Learn more about this case).
Consider the following example, which may cause data content to be repeated:
Because the MaritalStatus Transaction has the Autonumber property set to True for MaritalStatusId attribute and the Data Provider is defined as follows:
It's never going to happen that a duplicate key is detected when an insertion is tried (because always a new identifier value is generated). So, data content may be repeated. To avoid this, an alternative may be:
1) Not to set the Autonumber property = True for the MaritalStatusId identifier attribute.
2) The MaritalStatus_DataProvider has to be defined as follows:
Thus, each time the MaritalStatus_DataProvider is executed, when an insertion is tried a duplicate key is detected.
3) In order to obtain an autogenerated key for the MaritalStatusId attribute when the MaritalStatus Transaction is executed (through its form or as a business component), let's define the following rule in the MaritalStatus Transaction (to get the primary key value with the NextNumber Procedure defined by the developer):
MaritalStatusId = NextNumber() if MaritalStatusId.IsEmpty() on BeforeInsert;
For each MaritalStatus order (MaritalStatusId)
&NextId = MaritalStatusId + 1
&NextId = 1
4) The last thing to take into account is that the MaritalStatusId identifier attribute must be set as read-only and the MaritalStatus Transaction must be called with the different modes instantiated (for example from the corresponding Work With Web Panel). In this way, when the Transaction is executed in Insert mode, the identifier value is empty, the user can not enter any value to it and the NextNumber Procedure will be executed.
Note: Remember that we recommend using the Business Component concept so that the rules defined for the Transaction are triggered. If the developer decides to insert using the new command, the NextNumber procedure has to be called explicitly.