Adds a new item set as a parameter to a variable based on a Business Component collection.
&varBasedOnBCCollection.add(&varBasedOnBC)
Where:
&varBasedOnBCCollection
Is a variable based on a Business Component that is a collection.
&varBasedOnBC
Is a variable based on the same data type of the collection but corresponds to only one instance.
Consider the following two-level Transaction set as a Business Component:
Attraction
{
AttractionId* (Autonumber property = Yes)
AttractionName
CategoryId
CategoryName
CountryId
CountryName
CityId
CityName
AttractionLastTicketId
Ticket
{
AttractionTicketId*
AttractionTicketDescription
AttractionTicketPrice
}
}
that contains the following defined rule:
Serial(AttractionTicketId,AttractionLastTicketId,1);
Suppose you need to add a new ticket to the attraction whose AttractionName = Eiffel Tower.
To do so, define in a certain object (for example in a Web Panel object, Panel object or a Procedure object):
- An &Attraction variable based on the Attraction data type.
- An &AttractionTicket variable based on the Attraction.Ticket data type.
After that, in the context you are positioned (for example, in the Events section of a Panel object or in a Procedure source) write the following code:
&Id = Find(AttractionId,AttractionName="Eiffel Tower",0)
&Attraction.Load(&Id)
&AttractionTicket = new()
&AttractionTicket.AttractionTicketDescription = "Vip"
&AttractionTicket.AttractionTicketPrice = 200
&Attraction.Ticket.Add(&AttractionTicket)
&Attraction.Save()
If &Attraction.Success()
Commit
else
Rollback
endif
Read the article titled Business Component InsertOrUpdate method that presents another way to meet the same need.
Business Components Methods