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.):
To insert an Attraction, the code is:
&Attraction.AttractionName = "Eiffel Tower"
&Attraction.CountryId = 2 //France
&Attraction.CityId = 1 //Paris
&Attraction.Save()
Commit
Notes:
- 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.
To update the Attraction (for example, its category), the code is:
&Attraction.Load(1)
&Attraction.CategoryId = 1 //Monument
&Customer.Save()
Commit
To delete an Attraction, the code is:
&Attraction.Load(1)
&Attraction.Delete()
Commit
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:
&Attraction.Load(1)
If &Attraction.Fail()
&Attraction.AttractionName = "Eiffel Tower"
&Attraction.CountryId = 2 //France
&Attraction.CityId = 1 //Paris
&Attraction.CategoryId = 1 //Monument
Else
&Attraction.CategoryId = 1 //Monument
Endif
&Attraction.Save()
Commit
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
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.AttractionTicketId=1
&Ticket.AttractionTicketDescription="Without tour guide"
&Ticket.AttractionTicketPrice=100
&Attraction.Ticket.Add(&Ticket)
&Ticket = new()
&Ticket.AttractionTicketId=2
&Ticket.AttractionTicketDescription="With tour guide"
&Ticket.AttractionTicketPrice=150
&Atraction.Ticket.Add(&Ticket)
&Attraction.Save()
If &Attraction.success()
commit
else
rollback
endif
1. To update the first line price, the code is:
&Attraction.load(100)
&Attraction.Ticket.Item(1).AttractionTicketPrice = 130
&Attraction.Save()
Commit
2. To update the price of the ticket with description="Without tour guide", the code is:
&Attraction.load(100)
For &Ticket in &Attraction.Ticket
If &Ticket.AttractionTicketDescription="Without tour guide"
&Ticket.AttractionTicketPrice=110
Endif
Endfor
&Attraction.Save()
commit
To delete the first Attraction ticket, the code is:
&Attraction.load(15)
&Attraction.Ticket.Remove(1)
&Attraction.Save()
Commit
You can try the following URL. These are default for EV2.
http://localhost:8080/basename/servlet/invoce_bc_ws?wsdl
http://localhost/basename/invoce_bc.aspx?wsdl
|