Вы находитесь на странице: 1из 6

31/5/2018 Business Component samples

GeneXus Community Wiki (wiki?1755,Wiki+Home,)


Login Register

Try a Search

Business Component samples


(http://wiki.genexus.com/commwiki/servlet/wiki?34025,Type+of+content+available,)
Let's assume we define the Attraction transaction as Business component (wiki?
5846,Toc%3ABusiness+Component,) (by setting its Business component property (wiki?
9548,Business+Component+property,) = True):

(wiki?23736,AttractionTrnBC,)

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:

https://wiki.genexus.com/commwiki/servlet/wiki?2278,Business+Component+samples, 1/6
31/5/2018 Business Component samples

&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.
A er 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.Load(1)
&Attraction.CategoryId = 1 //Monument
&Customer.Save()
Commit

Sample c - Delete
To delete an Attraction, the code is:

&Attraction.Load(1)
&Attraction.Delete()
Commit

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:
 

https://wiki.genexus.com/commwiki/servlet/wiki?2278,Business+Component+samples, 2/6
31/5/2018 Business Component samples

&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:

(wiki?

23767,Attraction2LevelsTrn,)

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)


https://wiki.genexus.com/commwiki/servlet/wiki?2278,Business+Component+samples, 3/6
31/5/2018 Business Component samples

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

Samples f - Update an Attraction line (two cases)


     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

Sample g - Delete an Attraction line


https://wiki.genexus.com/commwiki/servlet/wiki?2278,Business+Component+samples, 4/6
31/5/2018 Business Component samples

To delete the first Attraction ticket, the code is:

&Attraction.load(15)
&Attraction.Ticket.Remove(1)
&Attraction.Save()
Commit

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.

http://localhost:8080/basename/servlet/invoce_bc_ws?wsdl
http://localhost/basename/invoce_bc.aspx?wsdl

Backlinks
Business Component (wiki?5846,Business+Component,)
Business Component Samples (Xpz files) (wiki?
11309,Business+Component+Samples+%28Xpz+files%29,)
Forward links
See all
Business Component (wiki?5846,Business+Component,)
Business Component property (wiki?9548,Business+Component+property,)
AttractionTrnBC (wiki?23736,AttractionTrnBC,)
More from mshuster
See all
SRC Messages (wiki?38589,SRC+Messages,)
Picture Properties Group (wiki?6800,Picture+Properties%C2%A0Group,)
Date format property (for Date/DateTime ... (wiki?
39441,Date+format+property+%28for+Date%2FDateTime+attributes%2Fvariables%29,)

https://wiki.genexus.com/commwiki/servlet/wiki?2278,Business+Component+samples, 5/6
31/5/2018 Business Component samples

J BY JLARROSA

— CREATED: 17 APRIL 2006 10:20 AM - LAST UPDATE: 5 AUGUST 2016 08:28 AM BY MSHUSTER

Was this page helpful?


(wiki?26969,,)
Your feedback about this content is important. Let us know what you think.
Sure! No

https://wiki.genexus.com/commwiki/servlet/wiki?2278,Business+Component+samples, 6/6

Вам также может понравиться