Automatic data population associated with Transactions - FAQ

Official Content
This documentation is valid for:

Here is a list of Frequently Asked Questions about Automatic data population associated with Transactions:

1. In which cases GeneXus automatically sets the Transaction Business Component property  = True, and in which cases can it be set explicitly?

When you set the Used 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 you set the Used 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). You can set it to True (Learn more about this case).

2. When is the data population run?

You can find the answer in the Used to property article.

3. How can you solve the case in which a Transaction needs an autogenerated key and as the associated Data Provider is executed several times it may cause data content to be repeated?  

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:


When an insertion is tried, a duplicate key is never going to be detected as a new identifier value is always 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.

  The MaritalStatus_DataProvider has to be defined as follows:


Thus, each time the MaritalStatus_DataProvider is executed, a duplicate key is detected when an insertion is tried.

2) To obtain an autogenerated key for the MaritalStatusId attribute when the MaritalStatus Transaction is executed (through its form or as a business component), you can define the following rule in the MaritalStatus Transaction (to get the primary key value with the NextNumber Procedure defined by you):

MaritalStatusId = NextNumber() if MaritalStatusId.IsEmpty() on BeforeInsert;
Procedure: NextNumber
Rule: Parm(out:&NextId);
For each MaritalStatus order (MaritalStatusId)
    &NextId = MaritalStatusId + 1
when none
    &NextId = 1

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 end-user cannot enter any value to it, and the NextNumber Procedure will be executed. 

Note: Remember that using the Business Component concept is recommended, so that the rules defined for the Transaction are triggered. If you decide to insert using the new command, the NextNumber Procedure has to be called explicitly.