Official Content

Allows the Transaction to be executed in a 'silent' mode (without showing its form) in order to update the database from any object.

Values

False
True

Scope

Objects: Transaction
Generators: .NET, .NET Framework, Android, Apple, Java

Description

The great advantage that the use of a Business Component provides is that you can update the database from any GeneXus object, and the same controls that are performed when the Transaction is executed will be done.

The default value for this property is False. 

When you set the Business Component property of a Transaction = True, a new data type named with the same name of the Transaction is created in the Knowledge Base, and variables based on that new data type may be defined in any object.

For example, suppose you define the Customer Transaction as Business Component (by setting its Business Component property = True):

Business Component Property Image

Once you set this property to True, a Business Component data type named Customer is automatically created in the Knowledge Base. Then, you will be able to define in any object a variable based on the new data type, as the following image shows (in the example in a Web Panel):

Variable defined with BC data type

The variables based on a Business Component data type (as &customer in this example), have got a set of properties that correspond to the Transaction attributes (so that you can assign them values).

Also, a set of methods is available to apply to Business Components variables (in order to execute operations in the database as insertions, updates, etc.).

Important: After assigning values to the properties of a Business Component variable and executing methods to update the database, it is necessary to write explicitly the Commit command in the code, wherever you consider that all the operations made to the database make a complete Logical Unit of Work (LUW).

Runtime/Design time

This property applies only at design-time.

Samples

Suppose the Customer Transaction shown above contains defined the following rule:

CustomerRuleImage 

and assume the CustomerId attribute has got its Autonumber property set to True.

The following code (included in the events section of the Web Panel where the &customer variable is defined) is inserting a customer by assigning values to the &customer variable properties (it means, the customer attributes), then the Save method is applied to the variable, and finally, the commit command is executed:

Event 'Insert customer'

 &Customer=new() //in this case, the new operator can be omitted, but if more than one customer is inserted, it must be used
 &Customer.CustomerName = 'John'
 &Customer.CustomerLastName = 'Smith'
 &Customer.CustomerAddress = '165 Ocean Drive'
 &Customer.CustomerEmail = 'jsmith@hotmail.com'
 &Customer.Save()
 if &Customer.Success() 
   commit 
 else 
   msg(&Customer.GetMessages().ToJson()) 
 endif

EndEvent

Several explanations related to the previous code:

When the Save method is executed:
- The default rule defined in the Customer transaction rule is triggered, so the CustomerAddedDate attribute is assigned.
- The CustomerId attribute is autonumbered.
- The CustomerPhone was not assigned, so, the attribute in the table will not contain a value (it will be empty).
- If the Transaction had had the CountryId attribute and/or the CityId attribute as foreign keys, and you assign by error values to them that not exist in the corresponding tables, when the Save method try to record, it fails.
- The mode changes to update, and the records keep instantiated in memory.
- After applying a method to access the database, it is recommended always handle the errors.

Since GeneXus 15 you can also use the Insert method instead of the Save method to solve the same customer insertion, as shown below:

Event 'Insert customer'

 &Customer=new() //in this case, the new operator can be omitted, but if more than one customer is inserted, it must be used 
 &Customer.CustomerName = 'John' 
 &Customer.CustomerLastName = 'Smith' 
 &Customer.CustomerAddress = '165 Ocean Drive' 
 &Customer.CustomerEmail = 'jsmith@hotmail.com' 
 if &Customer.Insert() 
  commit 
 else
  msg(&Customer.GetMessages().ToJson()) 
 endif 

EndEvent

How to apply changes

To apply the corresponding changes when the property value is configured, rebuild all the Transaction objects.

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant