Business Component samples

Official Content
This documentation is valid for:

Let's assume we define the Attraction transaction as Business component (by setting its Business component property = True):


Once we did it, a Business Component data type named Attraction is automatically created in the KB. Then, we will be able to define in any object a variable based on the new data type.

Let's suppose we define the &Attraction variable based on the Attraction data type in a certain object (for example in a web panel, or other object) and we codify the following basic samples in the section of the object that corresponds (events, source, etc.):

Sample a - Insert

To insert an Attraction, the code is:

   &Attraction.AttractionName = "Eiffel Tower"
   &Attraction.CountryId = 2                          //France
   &Attraction.CityId = 1                             //Paris


  • The CategoryId was ommited, but that foreing key allows nulls, so the record will be inserted without fails.
  • The AttractionId has its Autonumber Property = True, so it will be autonumbered by the database.
  • After executing the Save() method, &Attraction.Mode() is set to Update ("UPD") and all attributes are instanciated.

Sample b - Update

To update the Attraction (for example, its category), the code is:

   &Attraction.CategoryId = 1      //Monument

Sample c - Delete

To delete an Attraction, the code is:


Sample d - Insert or Update

The following code tries to load a certain Attraction record. If the operation fails because the record doesn't exist, the attraction is inserted. On the other hand, a category is assigned to the Attraction loaded:

   If &Attraction.Fail()
      &Attraction.AttractionName = "Eiffel Tower"
      &Attraction.CountryId = 2                      //France
      &Attraction.CityId = 1                         //Paris
      &Attraction.CategoryId = 1                     //Monument     
      &Attraction.CategoryId = 1                     //Monument

From now on, let's asumme the Attraction transaction has 2 levels as the following image shows:


The second level allows to store the different possible tickets to visit each attraction (with different peculiarities, prices, etc.).

The transaction Business Component property was set with True value, so GeneXus has created the Attraction data type associated with the first level transaction. And since it is a 2-level transaction, GeneXus also has created the Attraction.Ticket data type associated with the lines (second level), which in this example corresponds to the attraction’s tickets.

Then, in a certain object we define:

  • &Attraction: variable of the Attraction type
  • &Ticket: variable of the Attraction.Ticket type

Sample e - Insert an Attraction with 2 lines (tickets)

To insert an Attraction with two lines, the code is:

&Attraction.AttractionId = 100
&Attraction.AttractionName = "Louvre Museum"
&Attraction.CategoryId = 2
&Attraction.CountryId = 2
&Attraction.CityId = 1

&Ticket.AttractionTicketDescription="Without tour guide"

&Ticket = new()
&Ticket.AttractionTicketDescription="With tour guide"

If &Attraction.success()

Samples f - Update an Attraction line (two cases)

     1. To update the first line price, the code is:

  &Attraction.Ticket.Item(1).AttractionTicketPrice = 130

     2. To update the price of the ticket with description="Without tour guide", the code is:

  For &Ticket in &Attraction.Ticket
      If &Ticket.AttractionTicketDescription="Without tour guide"

Sample g - Delete an Attraction line

To delete the first Attraction ticket, the code is:



Sample h - how to call wsdl of bc in SOAP / what is URL of wsdl?

You can try the following URL. These are default for EV2.