Official Content

Once a new Knowledge Base is created, the next step is to describe the users’ visions. In order to do so, it is necessary to identify real-life objects (it is recommended to pay attention to the nouns that users mention in their descriptions, such as: products, invoices, customers, etc.) and start defining them by using GeneXus objects.

GeneXus developers don’t work on low-level tasks such as defining tables, normalizing, designing programs, programming, and the like. Instead, their work is a higher-level activity that implies describing the reality of users. After that, GeneXus analyzes the defined objects and goes on to design the database and the application programs for the selected platform in a totally automatic manner.

Consider the case where the pharmacy requesting the application asks to be able to record the products they have on sale.

To describe each identified real-life object, you have to create a GeneXus object of the Transaction type. 

How to create a Transaction object to describe the Products?

By selecting File > New > New Object in the main menu, the following dialog box will be displayed to allow you to select the type of object you want to create and enter a name for it.


You have to select the Transaction type of object and give it the name: Product

By clicking on the OK button, the Product Transaction is created and it keeps open ready for you to start to define it:


Each Transaction object has some sections that will be explained gradually.

In every Transaction object, the first section you always work with is with the Source.

Suppose that at the pharmacy you were told that they need to keep record of every product’s code, name, sale price, stock and its type (medicine, cosmetic, etc.). Therefore, these data that must be recorded for each product, matches the attributes or fields that have to be created for this Transaction.

To begin defining the attributes that describe the real-life object, place the mouse after the “{“ symbol and press the ENTER key.

Then, press the key with a period on the keyboard and the Transaction name will automatically be shown (“Product” in this case) as a prefix of the attribute name to be defined:


Type Code after the Product prefix to complete the attribute name:


In particular for the ProductCode attribute, type an “*” (asterisk) after the attribute name:


The reason for this is that in every Transaction object, an attribute – or set of attributes – must be set with the role of a unique identifier or Primary Key. Clearly, the primary key attribute of the Product Transaction is the product code.

With the focus positioned on the ProductCode attribute, look at the properties available to configure aspects of that attribute (its Data Type, Length, etc.).


The default Data Type for the attributes is: Numeric of 4 digits with no decimals. However, the pharmacy requested that the product code always be a numeric value of up to 10 digits, so you have to change its Length property to 10:


Note that, after updating the attribute Length property, next to the Attribute name, its data type is shown inside square brackets. If you like writing code instead of setting properties, you can type that syntax next to the attribute name.

Tip: The Properties window will be refreshed every time you select another attribute, object, etc., with the corresponding properties available for configuration in each case.

Now, place the cursor at the end of the line with the attribute recently defined (ProductCode) and press ENTER.

Continue defining the second attribute. Again, you have to press the key with a period on the keyboard, and GeneXus will automatically show the Transaction name (“Product”) as a prefix of the attribute name to be defined.

Complete the attribute name with Name, that is, ProductName. 

Define for this attribute:
•    Its Data Type property = Character
•    Its Length property = 50

Then, you will see the Source section of your Product Transaction like the following:


Next, you have to add the ProductPrice attribute (of the Numeric type, with 9 digits and 2 decimals) to the Product Transaction. So, place the cursor at the end of the line with the last defined attribute, press ENTER and proceed in the same way you have been defining attributes:


Pay attention to the white circle shown next to the name of the Product Transaction on the top tab of the object. It Indicates that the object is pending to be saved. Proceed saving (CTRL + S) and the white circle will disappear.

As you will probably need to create more attributes to define prices or amounts (i.e. when the pharmacy buys or sells products), it might be a good idea to create a generic definition type for all prices. To do this, in the Source section, in the line where the ProductPrice attribute is defined you just have to write: “Price=”, preceding the Numeric(9.2) data type, as shown:


Your Price definition with Numeric type (9 digits with 2 decimals) is called GeneXus Domains.

You may view the created domains in the Knowledge Base, by selecting View > Domains in the main menu or by clicking on the Domains node present in the KB EXPLORER window. Then, when you click on a certain domain, the Properties window is refreshed showing the properties available for configuration for that domain. In addition to setting the data type for a domain, you can also set other interesting properties for it.


So, the Prices domain is already defined in the Knowledge Base, it is assigned to the ProductPrice attribute and it can be assigned to other attributes that share the same definition.
Not only you can see that the Price domain is assigned to the ProductPrice attribute by looking at the Source section, but also you can observe the Based on property associated with the ProductPrice attribute and you will see that it has the Price domain assigned.


Tip: It is highly recommended to always define Domain names, Object names, Attribute names, etc. well descriptive. In particular naming attributes with the Transaction name as a prefix (remember to press the period key to obtain the prefix) not only makes defining attributes easier and faster, but is also a GeneXus community convention for easier comprehension when reading an attribute name wherever it may be present, as to know to which object it is describing.

Carry on defining the last attribute in the Product Transaction, ProductStock of the default data type (Numeric with length 4 and no decimals), so, you only have to define the attribute name and save.


Now select the Product Transaction Web Form tab:


Note that GeneXus has automatically designed a Web Form according to the attributes you have defined in its Source section. 

This form will enable users to add, update and delete products in runtime. It will not look exactly like this but more attractive.

Now it is necessary to record the product type. You could create an attribute called ProductType as Character(50)…


But what happens if the users want to enter two products of the same type? They would have to enter the same type name twice, being careful to type it exactly the same! Later on, they might need to search for all the products of a certain type, and to get them, the type must have been typed exactly the same.


It seems more reasonable to enter the type only once, in a single location, and then, for each product, to reference the corresponding product type. So, delete the ProductType attribute from this Transaction and leave it as it was defined.

Create another Transaction to allow recording product types, and after that, let’s assign a product type to each product. As already explained, to create a new object you have to select File > New > New Object in the main menu.

Tip: When creating an object, it will be created inside the Folder or Module in which you are positioned in the tree of the "KB Explorer" window (in the example inside the Root Module). Anyway, you can modify the Folder or Module that contain the object in the “New Object” dialog and even later if the object is already created, you can update the object property named Module/Folder.


Proceed defining in the ProductType Transaction the following attributes:
•    ProductTypeCode (primary key): Numeric(4.0)  
•    ProductTypeName: Character(50)


Now look at the properties available to set for the ProductTypeCode attribute.

Note that the Properties window includes a box to filter by property name.

Search for the Autonumber property. It is set to False by default. By changing it to True, all the new product types entered by the users will be automatically numbered in sequence. So, set the Autonumber property to True for this identifier attribute and save the ProductType Transaction.


The Autonumber property is offered only for attributes which are Numeric and simple primary key (not composed by several attributes).

As explained before, each Transaction has a Web Form automatically designed by GeneXus according to the attributes you have defined in its Source section. The following image shows the ProductType Web Form:


Remember to press CTRL + S to save your ProductType Transaction definition.

Now let’s assign a product type to each product.  Go back to the Product Transaction, place the cursor at the end of the line with the last defined attribute, press ENTER and type the first letters of the ProductTypeCode attribute:


By selecting the ProductTypeCode attribute, its entire definition is displayed.

In this Transaction let’s also include the ProductTypeName attribute, because when the users execute this Transaction and select a product type code, they will want to see the corresponding product type name in the form: 


Let’s focus on these two attributes included in more than one Transaction.

ProductTypeCode is the identifier attribute in the ProductType Transaction (more specifically, it is the primary key of that Transaction). So, when a primary key is included in another Transaction, GeneXus understands that there, the attribute has the role of foreign key.

Concept: Including an attribute that is a Transaction primary key in another Transaction allows you to relate both Transactions.

GeneXus establishes relations through attribute names, so when it finds attributes with the same name in different Transactions, it assumes that they refer to the same concept. 

The ProductTypeName attribute is also present in both Transactions. However, it is not marked as the identifier of any of the defined Transactions. Therefore, GeneXus will take it as a secondary attribute. GeneXus will then include ProductTypeName in the ProductType physical table that it will create in the database and not in the Product physical table.

Concept: The Transaction concept and the physical table concept are not the same. Keep in mind that Transaction is the GeneXus object that you create in the Knowledge Base to represent an object of reality. GeneXus considers the attributes present in each Transaction object, as well as analyzes the attributes names (and also taking into account some properties), it determines the physical tables that it must create in the database, and which attributes it must store in each table.

In runtime, when executing the Product Transaction Web form, the user must enter for the ProductTypeCode attribute (which is a foreign key attribute there), a value that has been previously recorded through the ProductType Transaction. Otherwise, an error will be displayed. After entering a valid ProductTypeCode, its ProductTypeName value will be obtained and shown on the screen.

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant