Business Component Fail method

Official Content

This method can be applied to a variable based on a business component type of a transaction, after executing the Save, Check, Load or Delete methods, in order to evaluate if the operation failed or not. 

It returns true if the operation failed. Otherwise, it returns false.

Syntax

&VbleBasedOnBCType.Fail()

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
}

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) try to delete a customer who has some miles to use:

&Customer.Load(15)
&Customer.Delete()
if &Customer.fail()
   &Messages = &customer.GetMessages()
   for &oneMessage in &Messages
         msg(&oneMessage.Description)
  endfor
else
  commit
endif

Variables defined in this object:

- &messagges: Messages data type (collection)
- &onemessage: Messages.message data type (1 element of the messages collection)


When the fail method is evaluated, it returns true because the error rule was triggered and the deletion couldn't be performed, so the code included in the if body, will be executed.


See also

Error handling in Business Components
Business Components Methods

 




Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.