Business Component Delete method

Official Content
This documentation is valid for:

The delete method executes something equivalent to what happens when the user presses the delete button in a transaction form.

When the method is executed (because it's applied to a variable based on a business component type of a transaction), the data previously loaded into memory by using the Load method (*), is deleted only if  the referential integrity doesn't fail (because it is checked) and if error rules don't occur (because the rules defined in the transaction are triggered).

(*) This is indispensable because the data to be deleted must be previously instantiated.


Syntax

&VbleBasedOnBCType.Delete()

Where:

&VbleBasedOnBCType
      Is a -temporary and local- variable defined in a GeneXus object, based on a business component type of a transaction.


Example

Let's suppose we 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 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 KB and we are able to define in any object, a variable of the new type created. Thus, in any object, we define a variable named &customer based on the Customer type.

The following code (defined for example in a procedure source or inside an event in a web panel) tries to delete the customer whose primary key CustomerId=25:

 &Customer.Load(25)
 &Customer.Delete()
 if &Customer.success()
     commit
 else
     rollback
 endif


Availability

This method is available since GeneXus 9.0.


See Also

Error handling in Business Components