Official Content

Executes something equivalent to what happens when the user presses the confirm button in a Transaction Form.

Syntax

&VarBasedOnBC.Save()

Where:
&VarBasedOnBC
     Is a variable defined in a GeneXus object, based on a Business Component.

Description

As this method is applied to a variable based on a Business Component, the formulas and rules defined in the Transaction are triggered and the referential integrity is checked, before saving physically the involved data.

It 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 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 you apply the Load method to the Business Component variable to instantiate certain data in memory first, and you assign values to the properties of the Business Component variable and save after that, GeneXus understands 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).

Samples

Suppose you define the following Transaction as Business Component (by setting its Business Component property = True):

Customer
{
  CustomerId*     (Autonumber property = True)
  CustomerName
  CustomerAddress
  CustomerPhone
  CustomerEmail
  CustomerAddedDate
  CustomerTotalMiles
}

Customer rule:

Default(CustomerAddedDate,&today);

Thus, a Business Component data type of the Customer Transaction is automatically created in the Knowledge Base 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 object) is inserting a customer:

  &Customer.CustomerName = 'Mary'
  &Customer.CustomerLastName = 'Brown'
  &Customer.CustomerAddress = '767 5th Avenue'
  &Customer.CustomerEmail = 'mbrown@gmail.com'
  &Customer.save()
  if &Customer.success()
     commit
  else
     rollback
  endif 


2) The following code (defined for example in a Procedure Source or inside an event in a Web Panel) is updating a customer:

  &Customer.Load(8)
  &Customer.CustomerEmail = 'marybrown@gmail.com'
  &Customer.save()
  if &Customer.success()
     commit
  else
     rollback
  endif

 

See Also

Error handling in Business Components





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