The Save method executes something equivalent to what happens when the user press the confirm button in a transaction form.
When it is executed (because it is applied to a variable based on a business component type of a transaction), the formulas and rules defined in the transaction are triggered and the referential integrity is checked, before saving physically the involved data.
This method can be used to insert and update physically. GeneXus understands the Save method is used to insert if you assign values to the properties of a variable based on a business component type and execute the Save method to the variable, but you haven't instantiated data in memory previously by using the Load method. On the other hand, if first of all, you apply the Load method to the business component variable to instantiate certain data in memory, and after that, assign values to the properties of the business component variable and save, GeneXus understand you are updating the data you have loaded as a first step.
It's essential to know that the Save method is only valid to be applied to business component variables of the transaction first level. This is easy to be understood since the behavior is the same as the Confirm button offers in a transaction form: when it is pressed, it saves all the data present in the form (belonging to all the transaction levels).
Is a -temporary and local- variable defined in a GeneXus object, based on a business component type of a transaction.
Suppose you define the following transaction as Business Component (by setting its Business Component property = True):
CustomerId* (Autonumber property = True)
Thus, a business component data type of the Customer transaction is automatically created in the KB and you are able to define in any object, a variable of the new type created. So, in any object define a variable named &customer based on the Customer type.
1) The following code (defined for example in a procedure source or inside an event in a web panel) is inserting a customer:
&Customer.CustomerName = 'Mary'
&Customer.CustomerLastName = 'Brown'
&Customer.CustomerAddress = '767 5th Avenue'
&Customer.CustomerEmail = 'firstname.lastname@example.org'
2) The following code (defined for example in a procedure source or inside an event in a web panel) is updating a customer:
&Customer.CustomerEmail = 'email@example.com'
Error handling in Business Components