Business Component Success 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 was successful or not.

It returns true if the operation was successful. Otherwise, it returns false.

Syntax

&VbleBasedOnBCType.Success()

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 Customer transaction as Business Component (by setting its Business Component property = True):

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

Rules:

Default(CustomerAddedDate,&today);
error('The customer must be 18 years old or more') if CustomerBirthDate.Age()<18;

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 insert a customer minor than 18 years:

&Customer.CustomerName='Tina Parker'
&Customer.CustomerAddress='18001 Collins Avenue'
&Customer.CustomerPhone= '877-219-8890'
&Customer.CustomerEmail= 'tinaparker@mail.com'
&Customer.CustomerBirthDate= ymdtod(2010,10,08)
&Customer.save()
If &Customer.success()
   commit
else
   &Messages = &customer.GetMessages()
   for &oneMessage in &Messages
       msg(&oneMessage.Description)
   endfor
endif

Variables defined in this object:

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

When the success method is evaluated, it returns false because the error rule was triggered and the save wasn't successful, so the code included in the else, 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.