Business Component GetOldValues method

Official Content
This documentation is valid for:

Obtains the previous value from a property of a variable based on a Business Component from the database.

Syntax

&VbleBasedOnBC.PropertyName.Getoldvalue()

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

Description

The objetive of applying this method to a property of a variable based on a Business Component, is to obtain the previous value that the property still has in store. It retrieves the value despite having modified it in memory; for example, by having assigned another value to it. 

The result returned by the method is a value that can be assigned to a variable or showed using Msg function, etc.

Samples

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

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

Rules:
Default(CustomerAddedDate,&today);
Error("The customer can't be deleted because he has miles to use") if delete and CustomerTotalMiles>0;

Accordingly, a Business Component data type of the Customer Transaction is automatically created in the Knowledge Base and you can define a variable of the new type created in any object. Thus, you can define a variable named &Customer based on the Customer type in any object . The following code can be defined in that object for example (if the object is a Procedure, the code can be included in its source):

&Customer.Load(1)                  
&Customer.CustomerTotalMiles += 500
msg('The customer has' + str(&Customer.CustomerTotalMiles.Getoldvalue()) + ' miles and now is going to have ' + str(&Customer.CustomerTotalMiles))
&Customer.Save()
commit


See Also

Business Components Methods