Getting Started with GeneXus 9.0

Latest Update: 2009

Getting Started With GeneXus 9.0

Copyright  Artech Consultores S.R.L. 1988-2009.

All rights reserved. This document may not be reproduced in any form without the express permission of Artech Consultores S.R.L. The information contained herein is intended for personal use only.

Trademarks

Artech and GeneXus are trademarks or registered trademarks of Artech Consultores S.R.L.

All other trademarks mentioned herein are property of their respective owners.

Page 1

Getting Started With GeneXus 9.0

Introduction ...... 3 System Requirements ...... 3 SQL Server 2005 Express Edition ...... 4 GeneXus Generators Requirements ...... 6 GeneXus Trial Version ...... 8 Trial Version Restrictions ...... 8 License Restrictions ...... 8 Technical Support ...... 8 Installation and Setup ...... 10 GeneXus Trial Version Authorization ...... 12 Getting Started: Step by Step Tutorial ...... 14 Knowledge-based Application Design ...... 14 Step 1: Creating a Knowledge Base ...... 15 Step 2: Creating a Transaction Object ...... 16 Step 3: Describing the Transaction Structure ...... 17 Step 4: Defining Calculated Fields  Formulas ...... 20 Step 5: Viewing the Data Model Inferred by GeneXus ...... 22 Step 6: Viewing the Transaction Object Forms ...... 25 Step 7: Creating Appealing Web Forms  Themes ...... 28 Step 8: Adding Business Rules  Rules ...... 30 Step 9: Creating the Transaction Object Customer ...... 31 Step 10: Reviewing the Data Model Changes ...... 35 Automatic Database Generation ...... 38 Step 11: Prototyping your Application ...... 38 Step 11-A: Prototyping your Application in .NET with SQL Server 2005 Express Edition ...... 38 Step 11-B: Prototyping your Application in JAVA with SQL Server 2005 Express Edition ...... 43 Step 12: Viewing the Database Creation Report ...... 49 Step 13: Creating the Prototype Model Database...... 52 Automatic Code Generation ...... 54 Step 14: Specifying and Generating your Code  Build Command ...... 54 Step 15: Viewing the Specification Report ...... 55 Fully Functional Prototyping ...... 58 Step 16: Running your Application ...... 59 Step 17: Testing your Application ...... 61 Incremental Development and Application Maintenance ...... 65 Step 18: Adding New Objects to your Project: Product Transaction Object ...... 65 Step 19: Reviewing Changes in your Data Model ...... 67 Step 20: Impact Analysis and Database Reorganization ...... 68 Step 21: Regenerating your Application Programs ...... 73 Step 22: Compiling and Running your Application ...... 75 Designing Non-Interactive Processes (Reports and Procedures) ...... 77 Step 23: Creating and Calling a Report ...... 77 Step 24: Specifying, Generating, and Running your Application ...... 87 Designing Interactive Queries and Dialogues (Work and Web Panels) ...... 89 Step 25: Creating a Web Panel: Work with Customers ...... 89 Step 26: Executing the Web Panel: Work with Customers ...... 99 Multi-platform Development...... 101 Summary...... 101 Contact and Resources ...... 103 GeneXus Community ...... 103 Support ...... 103 How to Buy ...... 103 Appendix I: GeneXus Models ...... 104

Page 2

Getting Started With GeneXus 9.0

Introduction

The goal of this document is to help you discover the power of the knowledge-based development methodology proposed by GeneXus and experience the key features of GeneXus. That is:

• Automatic data model design • Automatic code generation • Automatic database and code maintenance • Multi-platform development and deployment

System Requirements

The GeneXus Trial Version includes the following products:

• GeneXus Development Environment It is an Integrated Development Environment (IDE) for designing, developing and maintaining business applications, regardless of the production platform.

• GeneXus Generators GeneXus generates native code for all the leading platforms. For a complete list of GeneXus Generators, visit http://www.genexus.com/technologies . The GeneXus Generators available in the GeneXus Trial Version are the .NET Generator and the JAVA Generator.

Find below the list of hardware and software you will need in order to run GeneXus and the applications generated by it.

Hardware Requirements Processor: 500 MHz Intel Pentium class

Memory: at least 128 MB of RAM (256 MB recommended)

Page 3

Getting Started With GeneXus 9.0

Hard disk: at least 50 MB of free disk space to install the Development Environment, plus an average of 10 MB for each generator.

To create GeneXus applications, you will need additional space or a shared disk to create the generated application’s Knowledge Bases.

Video: 800 x 600 resolution or higher, with 256 colors

Software Requirements with NT technology; Microsoft Windows 2000 or higher. If you are using Windows NT, you must install service pack 6a or higher.

Microsoft .NET Framework 1.1 or 2.0 Redistributable Package 1

Microsoft Internet Explorer 6.0 SP1 or higher

Microsoft SQL Server 2005 Express Edtion or any of the GeneXus supported DBMS. For a complete list of supported DBMS, see: http://www.genexus.com/technologies

Adobe Re ader 6.0 or higher (in order to create pdf reports)

SQL Server 2005 Express Edition SQL Server 2005 Express Edition is the free, redistributable version of SQL Server 2005. To install and set it up, follow these steps:

1. Please review the Hardware and Software Requirements for SQL Server 2005 Express Edition: http://msdn2.microsoft.com/en-us/library/ms143506.aspx

2. Copy the setup file SQLEXPR.EXE file from the GeneXus 9.0 Evaluation CD (you will find it under D:\Software\Third Party Tools\Microsoft) to your local hard drive, or download the setup file from here: http://www.microsoft.com/sql/editions/express/default.mspx

1 The .NET Framework 2.0 Redistributable Package is required when using Microsoft SQL Server 2005 Express Edition. It can be obtained from the GeneXus 9.0 Evaluation CD (see Third Party Tools) or downloaded from Microsoft’s MSDN: http://msdn.microsoft.com/netframework/downloads/updates/default.aspx

Page 4

Getting Started With GeneXus 9.0

3. Open the Command Prompt, and execute the following command 2 from the directory where you copied the setup file:

sqlexpr.exe /q /qb ADDLOCAL=ALL, SECURITYMODE=SQL SAPWD=GeneXus!

Additional steps required to run Java applications:

1. Open SQL Server Configuration Manager; you will find in the Windows Start menu: Start/All Programs/Microsoft SQL Server 2005/Configuration Tools/. 2. In SQL Server 2005 Network Configuration/Protocols for SQL EXPRESS, enable TCP/IP Protocol. 3. In the TCP/IP Protocol window, disable Dynamic Ports and set 1433 as TCP Port.

Figure 1: Configuring the TCP Ports in SQL Server 2005 Express Edition

2 For more command prompt options read this article: http://msdn2.microsoft.com/en-us/library/ms144278.aspx

Page 5

Getting Started With GeneXus 9.0

GeneXus Generators Requirements This section contains the requirements to generate and execute applications with the GeneXus Generators available in the GeneXus Trial Version.

Generator Requirements

.NET • Microsoft .NET Framework Version 1.1 or 2.0 Redistributable Package 3. • For generating Web interface applications, you will need IIS 5.0 or higher (available on Windows Servers, Windows 2000 and XP Professional). • For generating Windows interface applications and printing PDF reports, you will need Visual J# Version 1.1 or 2.0 Redistributable Package 4 depending on your version of the .NET Framework, 1.1 or 2.0, respectively. • ADO.NET or ODBC Driver for the DBMS used. Java • J2SE Development Kit (JDK) 5.0 Update 6: http://java.sun.com/j2se/1.5.0/download.jsp • Nmake (Used to process .MAK files, NMAKE.EXE): http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN- US/Nmake15.exe ) • For generating Web interface applications: o Servlet Engine (i.e. Apache Tomcat 5) • For generating 3-tier Windows interface applications: o HTTP: you will need a Servlet Engine o CORBA: you will need Visibroker • JDBC Driver for the DBMS used 6.

In order to create your application’s database and execute the generated applications, you need to have one of the following DBMS:

• DB2 UDB for iSeries • DB2 Universal Database • Informix • Microsoft SQL Server (7.0 or higher or Microsoft SQL Server 2005 Express Edition)

3 The .NET Framework Version 2.0 Redistributable Package can be obtained from the GeneXus 9.0 Evaluation CD (see Third Party Tools) or downloaded from Microsoft’s MSDN page: http://msdn.microsoft.com/netframework/downloads/updates/default.aspx 4 The Visual J# Version 2.0 Redistributable Package can be obtained from the GeneXus 9.0 Evaluation CD (see Third Party Tools) or downloaded from Microsoft’s MSDN: http://msdn.microsoft.com/vjsharp/downloads/howtoget/default.aspx 5 The Apache Tomcat 5.0 can be obtained from the GeneXus 9.0 Evaluation CD (see Third Party Tools) or downloaded from http://tomcat.apache.org 6 If you will use SQL Server 2005 Express Edition as your DBMS, you need the jTDS 1.2 JDBC Driver. It can be obtained from the GeneXus 9.0 Evaluation CD (see Third Party Tools) or downloaded from http://jtds.sourceforge.net

Page 6

Getting Started With GeneXus 9.0

• MySQL • Oracle • PostgreSQL

Page 7

Getting Started With GeneXus 9.0

GeneXus Trial Version

Trial Version Restrictions The GeneXus Trial Version is fully functional and all the available generators remain authorized with a unique Site Key (without expiration date). However, some restrictions apply on the maximum number of GeneXus objects that you can create for a given Knowledge Base:

• Transactions: 30 • Work Panels (including the GeneXus selection prompts): 50 • Web Panels (including the GeneXus selection prompts): 50 • Procedures: 20 • Reports: 20

Other important restrictions are:

• Knowledge bases generated with the GeneXus Trial Version cannot be opened with a GeneXus standard version and vice versa. • The Knowledge Manager's "Distribution" option is disabled. The xpz extension files created with GeneXus Full versions can be consolidated (provided they do not exceed the limits mentioned above); i.e. you can consolidate projects but you can’t distribute them. • GeneXus Patterns can not be used with GeneXus Trial Version because there is no GXpublic Trial Version.

License Restrictions The GeneXus Trial Version is intended for evaluation and training only. Its installation is local and single-user. Network installation is not enabled.

Technical Support If you need assistance with your trial version installation and authorization, please contact [email protected]

If you are located in the USA or Canada, you may submit your support questions to [email protected]

To learn about the various GeneXus technical support and training services and resources, visit http://www.genexus.com/support and http://www.genexus.com/training

Page 8

Getting Started With GeneXus 9.0

For additional information, contact your local distributor: http://www.genexus.com/distributors or contact us at [email protected]

Page 9

Getting Started With GeneXus 9.0

Installation and Setup

1. Run the GeneXus Trial Version setup file (GX90Trial.exe) from the Windows Start menu or by selecting the appropriate option on your Trial Version CD.

Figure 2 GeneXus Trial Version Setup Wizard

2. Follow the GeneXus Trial Version Setup Wizard instructions. You need to install the GeneXus Development Environment and at least one GeneXus Generator.

Page 10

Getting Started With GeneXus 9.0

Figure 3 GeneXus Components selection dialog box

Page 11

Getting Started With GeneXus 9.0

GeneXus Trial Version Authorization

You need to authorize your GeneXus Trial Version the first time that you use it. To do so:

1. Execute the GeneXus Trial Version from the desktop shortcut or from the Start menu.

2. Write down or copy your Site Code from the GeneXus Trial Version Registration dialog box that will appear. TIP: Do not close this window!

Figure 4 GeneXus Trial Version Registration dialog box

3. Go to http://www.gxtechnical.com/trial/authorize ; this will open the GeneXus Trial Version Authorization page at GXtechnical. Login using your GXtechnical username and password, i.e. the same username and password that you used to download the GeneXus Trial Version.

4. Paste the Site Code in the appropriate field and click Submit .

5. You will receive your Site Key via email.

6. Type or paste your Site Key in the Site Key field of the GeneXus Trial Version Registration dialog box and click OK . A Site Key accepted message box will appear.

Page 12

Getting Started With GeneXus 9.0

Figure 5 Site Key accepted message

7. Finally, click OK on the Site Key accepted message and you are ready to start using your GeneXus Trial Version!

Page 13

Getting Started With GeneXus 9.0

Getting Started: Step by Step Tutorial

The objective of this tutorial is to provide you with an exciting first hands-on experience with GeneXus, as you learn the GeneXus Methodology fundamentals. Eventually, you will be able to create complex business-critical applications faster than you ever thought.

In this step-by-step exercise you will create a simple business application and deploy it on any of the platforms supported by the GeneXus Trial Version: .NET and JAVA. For a complete list of GeneXus supported platforms visit http://www.genexus.com/technologies/

As you work on this tutorial, you will experience the key features of GeneXus:

• Knowledge-based application design • Intelligent database generation • Automatic code generation • Fully functional prototyping at design time • Incremental development and automatic application maintenance • Non-interactive process design (reports and procedures) • Multi-platform development

Knowledge-based Application Design In this section you will learn how to create a GeneXus Knowledge Base and design an application based on the entities of your domain problem. In this particular case we will start by designing an invoice and other components needed in a Sales Management System.

Page 14

Getting Started With GeneXus 9.0

Business Analysts vs. Developers Understanding end-user needs is one of the few tasks that cannot be automated in software development. The GeneXus Methodology is based on describing the end-user entities (both tangible and intangible real objects) that your application deals with. This is done by describing the end users’ views of these entities at a high abstraction level. This is why we refer to GeneXus developers as business analysts rather than programmers, coders, or developers.

Step 1: Creating a Knowledge Base The first step to developing an application with GeneXus is to create a new Knowledge Base.

Key Concepts in this Step Knowledge Base : A GeneXus Knowledge Base is a repository of knowledge that contains all the information needed to generate an application in multiple platforms. A knowledge base is composed of several models:

• The Design Model : Contains all the application’s data requirements. The information contained in this model is shared by all the other models in the knowledge base. We always start by designing the application in the Design Model. • Prototype Models (usually one or more): Contains the design information specific to one or more prototype environments. • Production Models (usually one or more): Contains the design information specific to one or more production environments.

1. Open your GeneXus Trial Version

2. On the File menu, click New Knowledge Base .

3. Name the Knowledge Base Demo and click OK to continue. Figure 6 Knowledge Base creation dialog box

Page 15

Getting Started With GeneXus 9.0

Step 2: Creating a Transaction Object Use the GeneXus Transaction Objects to describe the real objects that your application deals with.

Key Concept in this Step Transaction Object : It represents the real objects that your application deals with. GeneXus uses these objects to infer the application’s data model (3 rd normal form). The transaction object is also used by GeneXus to generate the application program that will insert, delete, and update records in the physical database. Transaction objects are created exclusively in the Design Model.

To create the first transaction, which represents an invoice, follow these steps:

1. On the Object menu, select New Object.

2. Select the type of object that you want to create: Transaction .

3. Name the Object: Invoice .

4. Click OK .

Figure 7 New Object dialog box

Page 16

Getting Started With GeneXus 9.0

Step 3: Describing the Transaction Structure Describe the invoice object by describing its data structure and attributes.

Key Concepts in this Step The Transaction Object Structure is a description of the data needed to know the real object that it represents. In the structure, we must declare the attributes (fields) that make up the transaction (the data that the user will interact with) and the relationships between them. Based on this structure, GeneXus automatically designs and maintains the corresponding database (tables, keys, indexes, integrity constraints, etc.) in 3 rd normal form.

The key elements to define the transaction structure are:

• Attributes : Each attribute is defined by its name, data type, and description. • Levels : Attributes are grouped in one or more levels, and these levels may be nested or parallel (multiple nested levels are possible). For example: the lines in an invoice represent one nested level in the root level. The invoice line level represents the fact that one invoice may have many lines, i.e. it defines a one-to-many relationship between the invoice and the invoice lines. • Primary Key Attributes (PK) : One or more attributes in each level have to be defined as the Primary Key of the level. o The Primary Key is an identifier of each instance of the level. o Primary Key attribute values are unique and once entered, they cannot be updated. o If there is no “natural” Primary Key for your object, an “artificial” one must be created e.g. CustomerID.

1. Type the attributes’ name, data type, and description in the Invoice Structure tab based on the table below. Use the TAB key to move between the attribute name, data type, and description. Use the ENTER key to add a new attribute.

ATTRIBUTE TYPE DESCRIPTION

InvoiceID Numeric(4.0) Invoice ID

InvoiceDate Date Invoice Date

CustomerID Numeric(4.0) Customer ID

CustomerName Character(20) Customer Name

Press ENTER and then CTRL + Right (cursor key) to add a new level to the data structure

Page 17

Getting Started With GeneXus 9.0

ProductID Numeric(4.0) Product ID

ProductDescription Character(20) Product Description

ProductPrice Numeric(8.2) Product Price

LineQuantity Numeric(4.0) Line Quantity

LineTotal Numeric(8.2) Line Total

Press ENTER and then CTRL + Left (cursor key) to go back to the root level

InvoiceSubtotal Numeric(8.2) Invoice Subtotal

InvoiceTax Numeric(8.2) Invoice Tax

InvoiceTotal Numeric(8.2) Invoice Total

PRODUCTIVITY TIPS:

• When starting to type the name of a new attribute, typing on the period key will write the name of the transaction on the attribute name field. • Use CamelCase for your attribute names so that your attribute descriptions are automatically inferred. • When the data type combo box is selected, type the initial letter of the appropriate data type to select it. If it is a variable data type (Character, LongVarChar, Numeric, or VarChar), enter the appropriate value of the variable dimension to set it.

By default, the first attribute of each level is defined as the primary key of that level, but this can be changed by right-clicking on the attribute and choosing the Toggle Key option (Ctrl+K). Primary key attributes are identified by a little key to the left of their names. In this example, InvoiceID is the first-level identifier , and the ProductID attribute is the second-level identifier . This means that for a given invoice number (InvoiceID), the ProductID attribute value won’t be repeated in different lines.

Page 18

Getting Started With GeneXus 9.0

2. Right-click on the InvoiceID attribute and select Properties .

3. Set the Autonumber property of InvoiceID to True . The generated programs will automatically assign an InvoiceID value to each new Invoice instance.

Figure 8 Define Attribute (Properties) window

4. Save the new Invoice Structure by clicking on the diskette button on the Standard toolbar. If you don’t see this toolbar, choose View / Toolbars / Standard on the main menu.

You have just created the structure of an Invoice transaction composed of two levels:

• A base level (Invoice), where we specified all the information necessary for the Invoice Header. • A nested level, where we specified the information that will be repeated in every invoice line.

Note that we didn’t use Line ID as the invoice lines primary key. This is a conscious design decision. By using the Product ID as the invoice line primary key, we are defining that there won’t be two lines in the same invoice for the Figure 9 Invoice Structure same product.

Universal Relationship Assumption (URA)

Page 19

Getting Started With GeneXus 9.0

A key element of the GeneXus Methodology is that attributes with the same name are the same attribute; this is called Universal Relationship Assumption (URA), which says that:

• Everything that is conceptually equal should have the same name. • Different concepts CANNOT have the same name. This will enable us to use the same attribute in other GeneXus objects (other transactions, procedures, reports, etc.) by just referring to its name. GeneXus establishes the relationships (foreign keys) between the tables of the data model based on the attributes’ names.

GeneXus Incremental Knowledge -Based (GIK) Nomenclature

Artech has defined a loose but standard attribute nomenclature -GIK- which is widely used by the GeneXus community. In this nomenclature, an attribute name is made up of 4 components. Some of them are optional:

Object + Category [+ Qualifier] [+ Complement]

• Object: The real entity described by the attribute. This is usually (but not always) the name of the transaction in which an attribute has been defined, so that it will be stored in one of the tables associated to that transaction (this means that it should not be inferred in that specific transaction). Examples: Invoice, Customer, Product, Line. • Category: The attribute’s semantic category. It defines the role that the attribute will play inside the object and in the application environment. Examples: ID, Date, Invoice, Description, etc. • Qualifier and Complement are optional components. Examples: Start, End, Min, Max, etc.

Step 4: Defining Calculated Fields  Formulas

Key Concepts in this Step Formulas are attributes that can be inferred from the value of other attributes. A formula attribute is defined in the same way as a “normal” attribute, i.e. it has a name, data type, and description, plus a formula that defines how it is calculated.

• Unless otherwise specified, attributes defined as formulas will not be stored in the database (they are virtual attributes ).

Page 20

Getting Started With GeneXus 9.0

• Formulas are global ; they are valid across all the knowledge base and not only within the transaction where they are defined. This means that the formula is calculated each time that the attribute is invoked from a transaction or other GeneXus objects (Reports, Work Panels, etc). • User Defined Variables cannot be involved in a formula because they are local to the objects where they are defined, and they have no value outside them.

You will now define the following formula attributes:

• LineTotal = ProductPrice * LineQuantity • InvoiceSubtotal = SUM(LineTotal) • InvoiceTax = InvoiceSubtotal * .085 7 • InvoiceTotal = InvoiceSubtotal + InvoiceTax

1. Double-click on the Formula field of the LineTotal attribute (right of the attribute description).

2. Type the following expression: “ ProductPrice * LineQuantity ”. TIP : You can also right-click on the formula field and select the Edit formula… option to open the Formula Editor.

3. Repeat Steps 1 and 2 for the rest of the formulas listed at the beginning of this section.

4. Click Save to save the new formulas.

7 Note: Most likely, you will want to take the sales tax rate from a database table; in this example we hardcode the tax rate for simplicity.

Page 21

Getting Started With GeneXus 9.0

Figure 10 Invoice Transaction with formulas

Step 5: Viewing the Data Model Inferred by GeneXus You can view the data model inferred by GeneXus and, eventually, modify it.

Intelligent Data Model Generation

Whenever you click on the Save button, GeneXus infers the optimal data model (in 3 rd normal form, with no redundancies) that supports the end user entities represented by your GeneXus transaction objects. Based on this data model, GeneXus will generate a physical database when you define a target DBMS for a prototype or production model.

Key Concepts in this Step Intelligent Data Model Generation : The transaction objects structure determines the tables and indexes to be created.

• The table and index names are automatically assigned by GeneXus through the transaction name, but you can modify them if needed. • GeneXus infers a data model in 3 rd normal form, with no redundancies. However, you

Page 22

Getting Started With GeneXus 9.0

may define custom redundancies that will be automatically managed by GeneXus. • The primary key of a table corresponding to an n th level transaction is obtained by concatenating identifiers of the previous n-1 nested levels with the identifier of the nth level.

1. On the Tools menu, click List Database .

2. Clear the Modified check box if it is checked.

3. In the Select Object dialog box, click Select All and click OK . A Database Listing report will be generated.

Figure 11 Select Object dialog box

Page 23

Getting Started With GeneXus 9.0

Figure 12 Database (Data Model) Listing

The Database Listing shows that GeneXus automatically inferred a normalized data model, creating two tables to support the Invoice transaction object, Invoice (the invoice header) and Invoice1 (the invoice lines), with the following structure:

InvoiceID InvoiceID

InvoiceDate ProductID

CustomerID ProductDescription

CustomerName ProductPrice

LineQuantity

Note that:

Page 24

Getting Started With GeneXus 9.0

• The primary key of the Invoice1 table is composed of two attributes: InvoiceID and ProductID (the concatenation of the first-level identifier, InvoiceID, with the second- level identifier, ProductID). • GeneXus has automatically removed from the tables those attributes that we defined as formulas, and converted them into global formulas so you can access them from anywhere within the knowledge base. • In the Invoice table: o There can’t be two invoices with the same InvoiceID. o For each InvoiceID there is only one value of InvoiceDate, CustomerID, and CustomerName. • In the Invoice1 table: o There can’t be two invoice lines with the same InvoiceID and ProductID. o For each InvoiceID and ProductID pair there is only one value of ProductDescription, ProductPrice, and LineQuantity.

Step 6: Viewing the Transaction Object Forms Check the default GUI and Web forms automatically generated by GeneXus for your newly created transaction object.

Key Concepts in this Step GUI and Web Forms : After saving a new Transaction Object, a default (GUI) Form and Web Form are automatically created by GeneXus to specify how the end user will access data in GUI and Web applications, respectively. Both forms can be customized by the business analyst later on.

To view both forms, follow these steps:

1. Select the Form tab of the Invoice transaction.

Page 25

Getting Started With GeneXus 9.0

Figure 13 Invoice Transaction (GUI) Form

2. Select the Web Form tab of the Invoice transaction.

Page 26

Getting Started With GeneXus 9.0

Figure 14 Invoice Transaction Web Form

“Error Viewer: ctlError ” is the default control where error messages are displayed. We can place it on any part of the form and set properties for it. Possible messages are those displayed in Msg and Error rules, and automatic messages such as referential integrity, data type errors, etc.).

These forms will enable end users to enter new invoices that will be inserted as new records in the corresponding tables. Users will also be able to update or delete existing invoices, provided they have the rights to do so.

The GeneXus analyst doesn’t need to program any of these actions because they are implicit in the transaction logic. GeneXus automatically generates the corresponding native code in the selected language.

Note that when we define GeneXus transactions, we are:

• Explicitly: Describing the user interface for the data presentation and capture. • Implicitly: Designing the application’s data model (tables, indexes, etc.).

Page 27

Getting Started With GeneXus 9.0

Step 7: Creating Appealing Web Forms  Themes In this section you will create a new Theme based on a predefined template and set it as your application’s Theme.

Key Concepts in this Step Theme Object : The GeneXus Theme Object improves the development and maintenance of Web applications by separating the business analyst’s tasks from the Web designer’s tasks.

• Web Forms are created based on a default Theme Object. • Themes are defined using the GeneXus Theme Editor, a GeneXus utility distributed with GeneXus. • You can create new Themes and associate them to your entire Knowledge Base or to specific objects within it.

1. On the GeneXus Tools menu, select GX Theme Editor .

2. On the GX Theme Editor File menu, select Open / Template .

3. Open the Beach.xml template (find it in C:\Program Files\Artech\GeneXus\ GeneXus90Trial\KBTD ata\Templates )

4. Change the Forms background color (BackColor) by choosing Classes / Form and choosing Light Yellow on the Web Figure 15 GeneXus Theme Editor

tab.

Page 28

Getting Started With GeneXus 9.0

5. On the GX Theme Editor File menu, select Save As .

This saves the template as a Theme of our Knowledge Base.

6. Close the GX Theme Editor .

Figure 16 GeneXus Theme Editor Save As dialog box

7. On the GeneXus File menu, select Edit Model and then Properties .

8. Set Beach as the new Model’s Theme .

Figure 17 Model Properties

9. Select the Web Form tab of the Invoice transaction. You will see the previous Web Form now featuring the new Theme. Note: If the transaction was already open you may need to close and open it again to see the changes.

Page 29

Getting Started With GeneXus 9.0

Figure 18 Transaction Web Form with new Theme

Step 8: Adding Business Rules  Rules Add some basic business logic to your application.

GeneXus Rules

The GeneXus Rules are the way to define the business logic associated with each object. They are written in a declarative way; GeneXus intelligently decides which rule to apply and when.

Key Concepts in this Step Rules play a very important role in transaction objects because they make it possible to program their behavior (for example: assigning values by default; defining data controls, etc.).

Page 30

Getting Started With GeneXus 9.0

• They may involve attributes defined in the transaction structure, as well as variables, constants, and functions. • Rules are programmed in a declarative way i.e. the order in which they are written is not necessarily the order in which they will be executed. The proper execution order is determined automatically by GeneXus. • They are only valid in the transaction in which they are defined. This is why they are local .

We will now add a simple rule that sets the Invoice Date as today’s date by default:

1. Select the Rules tab of the Invoice transaction.

2. On the Insert menu, click Rule .

3. Select the Default rule (the first on the list) that assigns a default value to an attribute or variable. 4. Complete the formula as follows: “ Default(InvoiceDate, Today());” which indicates that the default value for the invoice Date will be today’s date. 8

5. Click Save .

Figure 19 Transaction rule

Step 9: Creating the Transaction Object Customer 1. Create the Customer transaction object by following Step 2: Creating a Transaction Object and Step 3: Describing the Transaction Structure .

2. Add the following attributes to the Customer Structure:

8 Note that you can also use the Insert / Attribute and Insert / Formula options from the Insert menu to complete the rule.

Page 31

Getting Started With GeneXus 9.0

ATTRIBUTE TYPE DESCRIPTION

CustomerID ------

CustomerName ------

CustomerAddress Character(50) Customer Address

CustomerEmail Character(50) Customer Email

Note that as you start typing the CustomerID and the CustomerName attributes, GeneXus prompts you the complete attribute names as well as their type and description. This happens because these attributes are already defined in your knowledge base.

3. Right-click on the CustomerID attribute and select Properties .

4. In the General tab, set the Autonumber property to True . Thus, the generated programs will automatically assign a CustomerID value to each new Customer instance.

5. In the Control Info tab set the following properties: • Input Type = Descriptions • Descriptions from = CustomerName • Suggest = Incremental This way, instead of inputting a CustomerID you will be able to type a CustomerName and the application will automatically infer its CustomerID. The suggest property will suggest you all the Figure 20 Define Attribute window CustomerNames that match your entry. These properties are part of the GeneXus implementation of AJAX .

The Customer Structure, (Windows) Form, and Web Form will look as shown below.

Page 32

Getting Started With GeneXus 9.0

Figure 21 Customer transaction Structure

Figure 22 Customer Transaction (Windows) Form

Page 33

Getting Started With GeneXus 9.0

Figure 23 Customer Transaction Web Form

Notice that the Invoice Web Form changed to reflect the changes in the CustomerID properties i.e. the CustomerName is now the CustomerID description attribute. This will greatly enhance the usability of the application, as we will see soon!

Page 34

Getting Started With GeneXus 9.0

Figure 24 Invoice Transaction Web Form

Step 10: Reviewing the Data Model Changes Review the new data model inferred by GeneXus (remember to Save your knowledge base so that the new data model is automatically inferred). To do so:

1. On the Tools menu, click List Database .

2. Clear the Modified check box if it is checked.

3. In the Select Object dialog box, click Select All and click OK . A new Database Listing report will be generated.

You will see that GeneXus has automatically normalized your data model after including the new transaction.

Page 35

Getting Started With GeneXus 9.0

(Continues on next page)

Figure 25 Database (Data Model) Listing

Note that:

• GeneXus added a new table: the Customer table (associated to the Customer transaction). • The CustomerName attribute has been removed from the Invoice table (this attribute is stored in the Customer table only), leaving the database normalized. • In the Customer table: o There can’t be two customers with the same CustomerID.

Page 36

Getting Started With GeneXus 9.0

o For each CustomerID there is only one value of CustomerName, CustomerAddress, and CustomerEmail. • In the Invoice table: o There can’t be two invoices with the same InvoiceID. o The CustomerID attribute in the Invoice table is a foreign key taken from the Customer table. Thus, there is a one-to-many relationship between Customers and Invoices:  For each InvoiceID there is one and only one CustomerID.  Each CustomerID may be in many Invoices (InvoiceID). • If you check the Show Detailed list option, GeneXus shows you the table indexes that it uses to maintain the referential integrity of your database as well as to access the tables efficiently. We will review this with more detail in Step 15: Step 15: Viewing the Specification Report .

Page 37

Getting Started With GeneXus 9.0

Automatic Database Generation So far, we’ve described the data requirements of our application as a series of GeneXus objects called transactions. GeneXus used this input to infer the optimal data model (3rd normal form) needed to support your transactions.

We did all the previous steps within the Design Model . The Design Model is the platform- independent model that we use to define the data model of our application. In order to generate a working application (database schema + source code + executable programs), we will use the Prototype and Production models.

Step 11: Prototyping your Application

Key Concept in this Step Prototype and Production Models : In order to generate and maintain a working application in a specific software platform, we need to define a Prototype or a Production Model . We do so by specifying a DBMS, a target language, and a few additional parameters for each Prototype or Production Model. GeneXus will generate and maintain the database schema and all the programs in the selected platform. Thus, the GeneXus analyst doesn’t need to have a deep knowledge of the target platform. For a graphic description of the relationships between components of the Design, Prototype, and Production Models, see Appendix I: GeneXus Models

You now have to choose on which platform you will generate the application: .NET or JAVA.

• To generate your application in .NET, please follow Step 11-A • To generate your application in JAVA, please follow Step 11-B

After Step 11, continue with Step 12 regardless of which platform you choose.

Step 11-A: Prototyping your Application in .NET with SQL Server 2005 Express Edition Before continuing, read the .NET Generator Requirements in the System Requirements chapter, and make sure that you have all the software required to execute the application.

Page 38

Getting Started With GeneXus 9.0

In this step we will generate a Prototype Model in Visual C# using SQL Server 2005 Express Edition as our DBMS. Alternatively, you may use any of the DBMS supported by GeneXus.

For a complete list supported DBMS, see http://www.genexus.com/technologies

1. Note that the creation of a new database is not performed by GeneXus. Therefore, before creating a Prototype or Production Model, create a new database in your DBMS and make sure that you have the appropriate rights to use it. In this sample, we will be using the “Master” database, which is created during the SQL Server 2005 Express Edition installation.

2. Select the Prototype environment from the Model Toolbar.

Figure 26 Model Toolbar detail

3. You will be prompted to create a new prototype model. Click OK .

Figure 27 Model creation dialog box

Page 39

Getting Started With GeneXus 9.0

4. The GeneXus Create Model Wizard will guide you while setting the parameters of the new model. Set: • Model Name: Prototype .NET • Language: .NET • User Interface: Web • DBMS: SQLServer • Target Path 9: leave default value

5. Click Next .

Figure 28 Create Model Wizard, Step 1

9 Target Path is the name of the folder where the Model files will be generated. This folder is located under the Knowledge Base folder, e.g. C:\Program Files\Artech\GeneXus\Demo\DATA002, where Demo is the name of the Knowledge Base. TIP: The Explore Model Target Path option on the Tools menu opens Windows Explorer on your current model folder.

Page 40

Getting Started With GeneXus 9.0

6. In Step 2 of the GeneXus Create Model Wizard, set:

• Access Method: ADO.NET • Database Name: Master 10 • Server name: \SQLEXPRESS

7. Click Next .

Figure 29 Create Model Wizard, Step 2

8. In Step 3 of the GeneXus Create Model Wizard, set:

• Use trusted connection: No • User id: sa • User password: GeneXus! • Declare referential integrity: No • SQL server version: 2005 or higher

9. Click Next .

10 The Database name, Server name, User id, User password, and SQL server version values used in this example are valid for SQL Server 2005 Express Edition. If you are not using SQL Server 2005 Express Edition you may need to set other values. The DBMS user needs to have creation rights.

Page 41

Getting Started With GeneXus 9.0

Figure 30 Create Model Wizard, Step 3

10. In Step 4, check that the Compiler and Virtual Directory paths are correct.

11. Click Next .

Figure 31 Create Model Wizard, Step 4

12. Step 5 is just a summary of your previous choices, so check that your options are correct (go Back if needed) and click Finish .

Figure 32 Create Model Wizard, Step 5

Page 42

Getting Started With GeneXus 9.0

13. Click OK . Because this is a new model, you will be prompted to create the physical database schema based on the data model inferred by GeneXus.

Figure 33 Database creation dialog box

Step 11-B: Prototyping your Application in JAVA with SQL Server 2005 Express Edition If you have followed Step 11-A, please go to Step 12

Before continuing, refer to the JAVA Generator Requirements in the System Requirements chapter, and make sure that you have all the software required to execute the application.

In this step we will generate a Prototype Model in Java using SQL Server 2005 Express Edition as DBMS. Alternatively, you may use any DBMS supported by GeneXus. For a complete list supported DBMS, see http://www.genexus.com/technologies

1. Note that the creation of a new database is not performed by GeneXus. Therefore, before creating Prototype or Production Models, create a new database in your DBMS and make sure that you have the appropriate rights to use it. In this sample, we will be using the “Master” database, which is already created in SQL Server 2005 Express Edition.

2. Select the Prototype environment from the model Toolbar.

Figure 34 Model Toolbar detail

Page 43

Getting Started With GeneXus 9.0

3. You will be prompted to create a new prototype model. Click OK .

Figure 35 Model creation dialog box 4. The GeneXus Create Model Wizard will guide you while setting the parameters of the new model. Set:

• Model Name: Java Prototype • Language: Java • User Interface: Web • DBMS: SQLServer • Target Path 11 : leave default

5. Click Next .

Figure 36 Create Model Wizard, Step 1 of 6

11 Target Path is the name of the folder where the Model files will be generated. This folder is located under the Knowledge Base folder (e.g. C:\Program Files\Artech\GeneXus\Demo\DATA003), where Demo is the name of the Knowledge Base. TIP: The Explore Model Target Path option on the Tools menu opens Windows Explorer on your current model folder!

Page 44

Getting Started With GeneXus 9.0

6. In Step 2 of the GeneXus Create Model Wizard set:

• Your JDBC driver • Use custom JDBC URL: No • Database name: Master 12 • Server name: localhost • Server TCP/IP port: 1433

7. Click Next .

Figure 37 Create Model Wizard, Step 2 of 6

12 The Database name, Server name, User id, User password, and SQL server version values used in this example are valid for SQL Server 2005 Express Edition. If you are not using it you may need to set other values. In any case, your DBMS user should have creation rights.

Page 45

Getting Started With GeneXus 9.0

8. In Step 3 of the GeneXus Create Model Wizard set:

• User id: sa • User password: GeneXus! • SQL server version: 2005 or higher

9. Click Next .

Figure 38 Create Model Wizard, Step 3 of 6

10. In Step 4 of the GeneXus Create Model Wizard, enter:

• The Servlet directory , i.e. the directory where the generated servlets will be transferred. In this example we use Jakarta Tomcat and the Servlet directory is: C:\Tomcat 5.0\webapps\servlets- examples\WEB-INF\classes • The Static content base URL , i.e. the relative directory of the webapp where the generated servlets will search for the static content (javascripts and images). • The Static content directory seen from client , i.e. the directory to which we will Figure 39 Create Model Wizard, Step 4 of 6 transfer the javascripts (the generated .js files). In this case: C:\Tomcat

Page 46

Getting Started With GeneXus 9.0

5.0\webapps\servlets- examples

11. Click Next .

12. In Step 5 of the GeneXus Create Model Wizard, set the following parameters:

• Platform: Sun SDK • Compiler Path: C:\jdk1.5.0_06\bin\javac.exe • Make Path: C:\java\nmake.exe • Interpreter Path: C:\jdk1.5.0_06\bin\java.exe • Classpath: gxclassr.zip;.;swt.jar; iText.jar;C:\Tomcat 5.0\common\lib\servlet- api.jar;D:\Software\Third Party Tools\Java\jTDS\jtds\jtds- 1.2.jar • Web Application Base URL: http://localhost:8080/servlets Figure 40 Create Model Wizard, Step 5 of 6 -examples/servlet/

13. Click Next .

Page 47

Getting Started With GeneXus 9.0

14. Step 6 is just a summary of your previous choices, so check that your options are correct (go Back if needed) and click Finish .

Figure 41 Create Model Wizard, Step 6 of 6

15. Click OK. Because this is a new model, you will be prompted to create the physical database schema based on the data model inferred by GeneXus.

Figure 42 Database creation dialog box

Before you proceed, check these important settings:

• The Servlet Engine shall be configured before started. Edit the file c:\Tomcat 5.0\conf\web.xml and uncomment the following paragraphs, i.e. delete the red marks:

Page 48

Getting Started With GeneXus 9.0

• The Servlet Engine shall be started before executing the application; Jakarta Tomcat is the one used in the example, and it can be started and stopped by the Tomcat Monitor (Windows Menu – Start – All programs – Apache Tomcat – Tomcat Monitor)

• Sometimes SQL Server 2005 Express Edition is not listening for TCP/IP connections, in which case you should go to Start>Run>“SVRNETCN” and enable the TCP/IP protocol.

Step 12: Viewing the Database Creation Report Read the Database Creation Report before creating the Prototype model database.

Automatic Database Generation

• When you are creating a new Prototype or Production model, GeneXus generates the executable programs required to create its database in the selected DBMS (in the Prototype or Production Model) based on the inferred data model (from the Design Model). • When you are updating a Prototype or Production model, GeneXus generates the executable programs required to reorganize the model database i.e. creating a new

Page 49

Getting Started With GeneXus 9.0

schema, and converting the data from the old schema to the new one. In these cases, a Database Creation Report or an Impact Analysis Report respectively, will show you what GeneXus will do.

Key Concepts in this Step Database Creation Report : Is the report that describes the database schema that GeneXus will generate in the target DBMS of your Prototype or Production Model. It contains all the information about the inferred data model and the proposed database schema to be generated. The information about each table is divided in four sections:

• Header : Contains the table name, actions to be performed on it, warnings, and errors. If the data model contains errors, the Reorganization button will be disabled. • Table Structure : Shows the table attributes, their relationships, and the actions to be performed upon them. • Indexes : Describes the table indexes that GeneXus uses to maintain the referential integrity of your database as well as to access the tables efficiently. • Foreign Key Constrains : Describes the table integrity restrictions.

1. Read the Database Creation Report. Note that you can select which table specifications you want to view.

Page 50

Getting Started With GeneXus 9.0

Figure 43 Database Creation Report

2. If you agree with the proposed database, click Reorganize .

Page 51

Getting Started With GeneXus 9.0

Step 13: Creating the Prototype Model Database

Key Concept in this Step GeneXus (Database) Reorganization : When you click on the Reorganize button of the Database Creation Report, GeneXus generates the database creation programs. The GeneXus Reorganization window is the front end of these programs and will guide you through the database creation process.

The same process will be repeated when changes in your data model require you to reorganize your database. In this case, you will generate and execute database reorganization programs.

1. When the database creation programs are ready to run you will be prompted to execute them. Click Yes .

Figure 44 Execute Reorganization dialog box

2. The database creation programs tell you that you need to reorganize your Prototype model database. Click on Execute .

3. When the “Reorganization completed” message appears on the GeneXus Reorganization window, click on Close .

Page 52

Getting Started With GeneXus 9.0

Figure 45 GeneXus Reorganization window

Page 53

Getting Started With GeneXus 9.0

Automatic Code Generation So far, we have created a new database schema that supports the data model inferred by GeneXus for our Prototype model. Next, we will generate the source code for our application in the language of your preference.

Step 14: Specifying and Generating your Code  Build Command In this step we will generate the code for our Prototype model. To do so, we will use the Build command.

Key Concepts in this Step Building is the process of creating the applications’ source code. It is composed of two consecutive steps:

1. Specification : This process generates a specification file for each GeneXus object in the Prototype or Production model. The specification file describes the GeneXus object behavior in an intermediate language that is independent from the application’s target language. These files have a “spc” extension. For each specification file, GeneXus generates a Specification Report (covered in the next step) that describes the object’s logic, and shows warnings or errors. Once an object (or set of objects) has been specified, the analyst may tell GeneXus to generate the application programs. 2. Generation : This process generates the source code for the application programs in the target language selected for the Prototype or Production model. This is done based on the information contained in the specification files.

1. On the Build menu, select Build All . You can also click on the Build All shortcut in the Model Toolbar.

Figure 46 Model Toolbar

Page 54

Getting Started With GeneXus 9.0

2. Select the Type of specification that we will use: Check specification .

3. Select Other Options: Specify & Generate .

4. Click on OK .

Figure 47 Build All dialog box

Step 15: Viewing the Specification Report

Key Concepts in this Step The Specification Report describes how the program will execute, which tables it will access (and how), and which operations it will perform.

The Transaction programs (programs associated with the transaction objects) enable the end user to Insert, Update, and Delete records from the database. They ensure the uniqueness 13 of the primary key, and that referential integrity and record locking are handled. All without you writing a single line of code!

Maintaining referential integrity implies preventing data inconsistencies due to updates, for example:

• Deleting a parent record with children records. • Inserting a child record without a parent record.

GeneXus displays a Specification Report composed of a series of Navigation Reports , one for each program that it will generate.

13 There shouldn’t be any tables in which two records share the same primary key value. In order to control this, when the end user tries to insert a record, it is automatically checked whether the value entered for the primary key exists as primary key of another record in the table. To perform this search efficiently, the table primary index is used.

Page 55

Getting Started With GeneXus 9.0

Figure 48 Customer Transaction Navigation Report

“Referential Integrity controls on delete” means that when you delete a customer from the Customer Transaction, the program will check that there aren’t any invoices for that customer. To perform this search efficiently, the foreign index CustomerID of the Invoice table is used.

Page 56

Getting Started With GeneXus 9.0

Figure 49 Invoice Transaction Navigation Report

Referential Integrity in the Invoice Transaction: The CustomerID foreign key in the INVOICE Level means that when you insert or update an invoice using the Invoice Transaction, it will be automatically checked that the value entered in the foreign key CustomerID exists as primary key of a record in the Customer table. To perform this search efficiently, the CustomerID primary index of the Customer table is used.

The referential integrity check validates that an entered attribute (e.g. CustomerID in an Invoice) is valid, but it doesn’t provide information on which are the valid values. In order to facilitate the search for a valid value, GeneXus creates Selection List objects (prompts) that show you the complete set of valid values to choose from.

Page 57

Getting Started With GeneXus 9.0

The Selection List objects added to your solution are:

• Selection List Invoice • Selection List Level1 • Selection List Customer

Figure 50 Selection list objects

Fully Functional Prototyping So far, we’ve designed our application (steps 1 to 9) as a set of transaction objects that map to real-life objects. GeneXus automatically inferred the best data model needed to support our data requirements. Then, we created a new database schema for a prototype application (steps 10 to 12). Finally, we specified and generated the source code of our prototype application programs (steps 13 and 14). We are now ready to test our application in the prototype environment!

Pr ototyping Your Application with GeneXus You can define as many prototype and production models as desired. Even though both types of models are identical with respect to the supported features, it is strongly recommended that you define at least one prototype model for each production model.

Why Prototyping?

The design process entails all the hurdles of human communication: • The user forgets certain details. • The analyst doesn’t notice some issues. • The user conveys some wrong approaches. • The analyst misinterprets some of the user's explanations.

Prototyping reduces the risk of a faulty implementation in several ways: • Without prototyping, design issues will only be detected during the system's final tests. The cost of solving them at this stage will be very high. • Reality changes, so it is not reasonable to think that your system specifications can be frozen while the system is being implemented. • Freezing the specifications at the design stage will surely lead to an unsatisfactory solution.

Prototyping bridges the gap between the design and the implementation stages of your

Page 58

Getting Started With GeneXus 9.0

system.

A GeneXus Prototype is an application "ready-to-work" that is functionally equivalent to the final production application. The prototype is intended to run on PC environments, but it can run on any selected platform. GeneXus is capable of generating code for the following languages: C# (for the .NET Framework and .NET Compact Framework), Java, C/SQL, Cobol for iSeries, RPG for iSeries, (standalone and C/S), Embedded Visual Basic, and Visual Fox Pro (standalone and C/S). The prototype enables you to test your application’s functionality before it is put into production. Your end user can easily test screens, reports, formulas, business rules, data structures, etc.

Working with a Prototype consists of: • Managing the physical database associated with the Prototype Model. • Executing the Prototype Model application for evaluation.

Step 16: Running your Application 1. On the Build menu, click Run . You can also click on the Run sh ortcut in the Model toolbar (last button on the right), or just press F5 .

Figure 51 Model toolbar

Page 59

Getting Started With GeneXus 9.0

2. Click Compile in the Execution dialog box to compile your application.

Figure 52 Execution dialog box

3. A GeneXus Compilation window will appear. When the Task Status changes to Succeeded, press Close .

4. Click Execute in the Execution dialog box to run the application. 14

Figure 53 GeneXus Compilation dialog box

14 The ASP.NET process account (ASPNET by default) of your machine shall have Read & Execute, List Folder Contents, and Read rights on the folder that contains the web application e.g. C:\Program Files\Artech\GeneXus\Demo\DATA002\web

Page 60

Getting Started With GeneXus 9.0

Step 17: Testing your Application When you execute the compiled application from the prototype model, a fully functional prototype will run.

1. The Developer Menu is an XML file that features all your executable objects. It is an auxiliary menu for prototyping your application. Click on the Customer option (If you are using Internet Explorer right click on Customer and choose Open in New Window).

Figure 54 Developer Menu

Page 61

Getting Started With GeneXus 9.0

2. Enter a few customer instances so as to use them in future invoices.

3. When you have finished, click on the Close button.

Figure 55 Customer Transaction instance

Page 62

Getting Started With GeneXus 9.0

4. Click on the Invoice option (If you are using Internet Explorer right click on Customer and choose Open in New Window).

5. Enter some data into the Invoice . While you do so, notice a few things: • The invoice date is already set as today’s date thanks to the Default rule defined in Step 8: Step 8: Adding Business Rules  Rules . • You don’t need to input or look up the Customer ID in a selection list, you just type the first letters of his or her name and the generated application will suggest you the customers’ names that start with those letters. This is thanks to the generated AJAX code. Remember that we set that CustomerID as described by CustomerName and requested GeneXus for the generated application to suggest values. • Formulas are automatically calculated as you move from field to field, also thanks to the GeneXus AJAX implementation. • You need to click on the Apply Changes button twice to confirm your data input.

Figure 56 Invoice Transaction instance

Page 63

Getting Started With GeneXus 9.0

6. When you have finished, click on the Close button.

Page 64

Getting Started With GeneXus 9.0

Incremental Development and Application Maintenance So far, we have created a working application based on a few transaction objects and business rules. We will now see how to maintain a GeneXus application just by editing the existing GeneXus objects and/or adding new ones and then automatically refactoring your database and regenerating your application programs.

Incremental Development with GeneXus As reality changes, system requirements will evolve and this will translate into changes in the GeneXus objects and/or new objects. Based on the new objects, GeneXus will automatically refactor your database (create a new database schema and migrate the data from the old to the new schema) and regenerate the application programs that need to be modified.

We say that the GeneXus Methodology is incremental because it is based on the assumption that system development is an iterative process that goes through successive approximations. Incremental development is possible because GeneXus can automatically maintain your database schema and your application programs.

Step 18: Adding New Objects to your Project: Product Transaction Object While following Step 17: Testing your Application you may have noticed that you needed to enter the Product ID, Description, and Price in each invoice line. This is not what you would expect from a sales management system. Not even from a simple system such as this sample application!

We need the possibility of adding, updating, and deleting products in our system. To do so we will add the Product transaction to our Knowledge Base:

1. Select Design in the drop -down menu of the Model toolbar to go back to the Design Model. Remember that all the data modeling will be done in the Design Model only (in any prototype or production model, the option of creating new transactions is disabled).

2. Create the Product transaction by following Step 2: Step 2: Creating a Transaction Object and Step 3: Step 3: Describing the Transaction Structure . Insert the following attributes in the Product Transaction Structure:

Page 65

Getting Started With GeneXus 9.0

ATTRIBUTE TYPE DESCRIPTION

ProductID ------

ProductDescription ------

ProductPrice ------

Note that as soon as you start typing these attribute names, GeneXus prompts you their complete name. This happens because these attributes are already defined in your Knowledge Base.

The Product transaction Structure, (Windows) Form, and Web Form will look as shown below.

Figure 57 Product Transaction Structure

Page 66

Getting Started With GeneXus 9.0

Figure 58 Product Transaction (Windows) Form

Figure 59 Product Transaction Web Form

Step 19: Reviewing Changes in your Data Model As you save the Product transaction object, GeneXus will normalize the data model once again. Reviewing the data model (menu option Tools / List Database ) reveals that GeneXus has automatically normalized the data model, moving the ProductDescription and ProductPrice attributes from the Invoice1 (Invoice Detail) table to the new Product table.

Page 67

Getting Started With GeneXus 9.0

Figure 60 Database (Data Model) Listing for Invoice1 and Product tables

Step 20: Impact Analysis and Database Reorganization Go back to your Prototype Model and perform an Impact Analysis on it.

Key Concepts in this Step Impact Analysis : Whenever you go from the Design Model to a Prototype or Production Model (the target model), GeneXus assesses whether the physical database of the target model needs to be updated to match the data model of the Design Model. If so, GeneXus analyses the impact of the changes on the target model’s database. This is called Impact Analysis and produces an Impact Analysis Report that contains:

• A description of the data conversion (reorganization) to be done. • Warnings about potential problems that may occur during the reorganization process (inconsistencies produced by new rules applied to old data, etc.).

Based on the information presented on the Impact Analysis Report, you can decide whether or not to go ahead with the reorganization process. Reorganization or Conversion Programs : When you are ready to proceed with the database

Page 68

Getting Started With GeneXus 9.0

reorganization in the target model, you create the Reorganization Programs and execute them. The reorganization programs create a new database schema in the target model’s physical database and move the data from the old to the new schema. This process is usually referred to as database refactoring, which in this case is done automatically by GeneXus.

1. Select Prototype in the drop -down menu of the Model toolbar.

2. You will be prompted to perform an Impact Analysis. Click OK .

Figure 61 Impact Analysis dialog box

3. The Impact Analysis Report describes the changes needed in the Prototype Model physical database to match the current data model in the Design Model.

Page 69

Getting Started With GeneXus 9.0

Figure 62 Impact Analysis Report

4. Click on the Reorganize button of the Impact Analysis Report to generate the reorganization programs.

5. When the reorganization programs are ready to run, you will be prompted to execute them. Click Yes .

Figure 63 Execute Reorganization dialog box

Page 70

Getting Started With GeneXus 9.0

6. The reorganization programs tell you that you need to reorganize your Prototype Model database. Click on Execute (the Reorganization).

Figure 64 GeneXus Reorganization dialog box

7. When the “Reorganization completed” message appears on the GeneXus Reorganization window, click on Close .

Now the physical database of your Prototype Model matches the data model defined in your Design Model!

Figure 65 GeneXus Reorganization dialog box

Page 71

Getting Started With GeneXus 9.0

Page 72

Getting Started With GeneXus 9.0

Step 21: Regenerating your Application Programs Once your Prototype (or Production) Model database is synchronized with the Design Model data model, you will regenerate the application programs of your Prototype (or Production) Model. For more information, see the Automatic Code Generation section.

To regenerate your application programs:

1. On the Build menu, click Specify or press SHIFT + F8 to display the Select Object dialog box.

2. Check the Modified After Specification option to specify only those objects that have changed after the last specification.

3. Click OK .

Figure 66 Select Object to Specify dialog box

4. In the Specify Objects dialog box, select the Check specification option and click OK .

Figure 67 Object specification dialog box

Page 73

Getting Started With GeneXus 9.0

5. In the resulting Specification Report , click Generate to generate the programs associated to the Product Transaction. Note that GeneXus has automatically added a Selection List object to be specified and generated. These programs will be generated in the corresponding native code of the Prototype (or Production) Model.

Figure 68 Specification Report

Now your application programs are ready to be compiled and executed!

Page 74

Getting Started With GeneXus 9.0

Step 22: Compiling and Running your Application Your Prototype Model database has already been refactored, and your application programs’ code has been generated. For more details, see the Fully Functional Prototyping section on page 38. Now it’s time to compile and execute your application. To do so, follow these instructions:

1. Press F5, and click Compile in the Execution dialog box.

2. Close the GeneXus Compilation window.

3. Click Execute in the Execution dialog box 15 .

Figure 69 Execution dialog box

15 If you are using Mozilla Firefox (and other browsers) you may need to refresh the GeneXus Programs window to see the Product option.

Page 75

Getting Started With GeneXus 9.0

4. Click on the Product option on the Developer Menu.

Figure 70 Developer Menu

5. Click the Select button to view the items that you had originally entered directly into an invoice.

This means that the reorganization programs not only changed the database structure, but also maintain the information already stored in your database.

Figure 71 Product Selection List

Page 76

Getting Started With GeneXus 9.0

Designing Non-Interactive Processes (Reports and Procedures) Reports and Procedures

So far, we have worked with Transaction Objects, which are GeneXus objects that require the user’s intervention to insert, update and delete records in the database. However, on many occasions we need to perform tasks without user intervention. To do so, we use two other types of GeneXus Objects:

• Reports : Define non-interactive processes to query the database. The report output is usually sent to a printer or displayed on the screen. Reports do not update the database. • Procedures : Define non-interactive processes to query and update the database (procedures can do all that reports do in addition to updating the database). Procedures are used to define functions and subroutines.

A key feature of GeneXus Reports and Procedures is that we use the same knowledge-based methodology that we used to define the Transaction Objects. This means that the definition of these objects is based on attribute names and not on the database tables where those attributes are stored. Therefore, your Reports and Procedures definitions remain valid as long as the declared attributes within them are present in the knowledge base.

In our example we will create a simple Report (one that shows all the data of an invoice). Note that Reports and Procedures are one of the most powerful features of GeneXus. We strongly encourage you to read the reference materials before building a real project.

Step 23: Creating and Calling a Report

Key Concepts in this Step Reports and Procedures

GeneXus Reports and Procedures share the following key features:

• Procedural : Reports and Procedures are specified in a very high level, procedural way. The execution sequence is determined by the analyst using a simple procedural language that includes control, printing, data access, and other commands. • Knowledge-based : The Reports and Procedures’ source code refers to attribute names in the Knowledge Base, not to their location in the (Prototype or Production Model) physical database. Thus:

Page 77

Getting Started With GeneXus 9.0

o GeneXus knows where to find the attributes in the physical database. o GeneXus knows the relationships between the tables in the physical database. o Formula Attributes are automatically inferred by GeneXus. o Changes in the physical database will not affect the Reports and Procedures behavior.

Since there won’t be any database schema changes, we will create a report in the Prototype Model; we will call this report by adding a print button to the existing Invoice object.

1. On the Object menu, click New Object .

2. Select the Object Type that you want to create: Report .

3. Name the Object: “Invoice” and click OK .

Figure 72 Define Object dialog box

Page 78

Getting Started With GeneXus 9.0

4. Click Insert from Trn… (Transaction) in the report wizard that will appear.

The Insert from Transaction option is actually a shortcut to create a report whose structure is exactly the same as the selected transaction. However, you can create reports that are composed of attributes from multiple transactions, in any Figure 73 Report Wizard, Step 1 of 4 meaningful order.

Page 79

Getting Started With GeneXus 9.0

5. Select the Invoice transaction and click OK.

Figure 74 Select Object dialog box

Page 80

Getting Started With GeneXus 9.0

6. Click Finish .16

Figure 75 Report Wizard, Step 1 of 4 (Invoice Structure selected)

16 Note that we are skipping steps 2 through 4 of the Report Wizard. These steps enable us to specify several format and layout settings. In this case we choose to apply all the default settings.

Page 81

Getting Started With GeneXus 9.0

7. Click on the Layout tab of the Invoice Report to view its Printing Blocks. Each Printing Block may contain a set of controls such as attributes, variables, labels, etc.

Figure 76 Invoice Report, Layout tab

Page 82

Getting Started With GeneXus 9.0

8. The navigation structure (which data is going to be listed, and in what order) is defined in the Source tab. In this case, the Report Source Code was automatically generated by GeneXus.

Figure 77 Invoice Report, Source tab

Page 83

Getting Started With GeneXus 9.0

9. On the Object menu, select Properties to view the report’s properties.

10. Set the Main program property to True.

11. Set the Call protocol to HTTP.

12. Set the Report Output property (expand the Options group to view it) to Only To File and click on OK .

Figure 78 Report Properties window

Finally, in order to in voke the Invoice Report from the Invoice Transaction we will use two simple rules:

13. In the Invoice Report, select the Rules tab.

14. Write: Parm(InvoiceID); Output_file('Invoice', "pdf");

15. Click Save . Figure 79 Invoice Report, Rules tab

Page 84

Getting Started With GeneXus 9.0

16. In the Invoice Transaction, select the Rules Tab.

17. Add the following rule: Call(RInvoice, InvoiceID) ON AfterComplete;

Figure 80 Invoice Transaction, Rules tab

At this point it is important to introduce two key GeneXus concepts: Extended table and For Each command.

Extended Table

Given a base table , its extended table is the group of attributes that are directly or indirectly determined by the base table key:

• Attributes that belong to the base table. • Attributes that belong to all the tables which are directly or indirectly in an N to 1 relationship with the base table.

Uses:

• The extended table concept enables GeneXus reports and procedures to remain valid when the database structure changes. • The extended table is also used by transaction objects, which can insert, update, and delete attributes that belong to the extended tables of the base tables referenced in the transaction structure.

In order to find the extended table of a given table you may use the Bachmann n Diagram of the knowledge base data model:

1. In the Tools menu, select Diagrams 2. Check the Table diagram type, and click on New 3. Select the tables that you want to display and click OK .

Page 85

Getting Started With GeneXus 9.0

Figure 81 Data Model Bachmann Diagram

Based on this diagram we can identify the extended tables of every table in our project:

Base table Extended table

Customer Customer

Product Product

Invoice Invoice, Customer

Invoice1 Invoice1, Invoice, Customer, Product

For Each Command

The “For Each” command is the core of the procedural language used by GeneXus to define reports and procedures. It retrieves and updates information (through online procedures) from your database.

With the For Each command you define the information you want to access by naming the attributes to be used. The appropriate tables will be automatically inferred by GeneXus at generation time. When the database structure changes, the For Each definitions remain valid.

The For Each basic syntax is as follows:

for each print

Page 86

Getting Started With GeneXus 9.0

endfor

Every For Each command has an associated data model table that will be navigated. It is composed of the For Each base table and its extended table (the tables that GeneXus needs to access to look for the attributes mentioned in it).

• The tables that will be accessed are determined by the attributes contained in the For Each command. • For this group of attributes, GeneXus will infer the minimum extended table. • The base table of this group of attributes will be the For Each base table.

Step 24: Specifying, Generating, and Running your Application 1. Specify and run the application following Step 14: Specifying and Generating your Code  Build Command through Step 16: Running your Application .

2. On the Developer Menu select Invoice , and enter a new invoice or select an existing invoice. Next, click on Apply Changes twice. The rule that calls the report will be triggered and it will be displayed on your browser.

Page 87

Getting Started With GeneXus 9.0

Figure 82 Invoice Report

Page 88

Getting Started With GeneXus 9.0

Designing Interactive Queries and Dialogues (Work and Web Panels)

Step 25: Creating a Web Panel: Work with Customers Work and Web Panels

Work Panels are used to make interactive dialogues and queries to the database in a GUI or Windows environment.

Web Panels are equivalent to Work Panels for the Web environment. However, there are some important differences between them due to the disconnected nature of Internet. In Web Panels, dialogues and query results are formatted as HTML pages at execution time and sent to the browser.

Work and Web panels are programmed using a simple event-driven language.

Key Concepts in this Step Event-Driven Programming : It is a programming style in which applications contain code that remains idle until called to respond to events triggered by the user or by the system. User-Defined Events : They are events created by the analyst. These events have a name and code which is executed only when the end user clicks on the key or button associated with that event.

System Events: The following events are defined by default on Work and Web Panels.

• Start : Occurs only once, when the Work or Web Panel execution begins. Every time that we execute a work panel, the first thing to be executed is the code associated to the start event. • Refresh : Occurs only once, just before the data is loaded from the database to the grid. • Load : See “Data Loading” below. • Enter : The code associated to this event is executed every time the user presses Enter or the “Confirm” button. • Exit : Occurs only once, at the end of the Work or Web Panel execution. Every time that we close a work panel, the last thing to be executed is the code associated to the exit event. Work and Web panels can be closed with the Close button or the exit key (ESC or F12), or if the “return” command included in an event is executed.

Data Loading : GeneXus retrieves the data to be displayed on Work and Web Panels in the same way as that used in Report and Procedure Objects. In this case, GeneXus performs an implicit For Each based on the following attributes:

• All the attributes displayed on the form.

Page 89

Getting Started With GeneXus 9.0

• All the attributes used in events, except for those included in For Each commands defined by the analyst in the Work or Web Panel (these will not be considered in the implicit For Each). • All the grid attributes that are hidden, i.e. those hidden using the “Hide” button in the “General” tab of the grid properties dialog. • All the grid attributes that have been inserted on the “Grid Order” screen. This screen is accessed through the “Order” option in the pop up menu displayed by right-clicking on the grid. • All the grid attributes that have been used in the grid conditions.

With all these attributes, GeneXus infers the corresponding base table. Then, it navigates the base table inferred and accesses the extended tables to retrieve the grid attribute values, both visible and hidden. For each record found, the code associated to the Load event is executed and then the record is loaded in the grid.

Event Handling in Web Panels : When a web user accesses a Web server page to view it, the Browser downloads the page to the client. After that, it’s impossible to detect what the user is doing on the client side, until the user triggers an event such as Enter. When the user clicks on Enter, the modified page is sent (submitted) to the server to continue with the process.

The first time a Web Panel is executed (Get), the corresponding events are triggered in the following order:

1. Start 2. Refresh 3. Load

Then, when a button associated to the Enter event or to a user event is pressed, or when an event associated to an image (which does not call another web panel) is executed by clicking on it, the web panel will be executed again and the triggering order will be as follows (Post):

1. Start 2. Read variables on the screen 3. Enter event or user defined events 4. Refresh 5. Load

The order of events clarifies the concept of “submitting” the values entered by the user.

To create a Web panel, follow these steps:

Page 90

Getting Started With GeneXus 9.0

1. On the Object menu, click New Object .

2. Select the Object Type that you want to create: Web Panel .

3. Name the Object: “Customers”

4. Describe the Object as: “Work with Customers”.

5. Click OK.

Figure 83 Define Object dialog box 6. The Web Panel empty Form will appear. Write: Work with Customers

7. Use the Format button in the Formatting Toolbar to set this text as Heading 1.

8. Press Enter .

Figure 84 Web Panel Form with Formatting Toolbar

Page 91

Getting Started With GeneXus 9.0

9. On the Insert menu, select Grid . The Attribute / Variable Selector window will appear.

10. Write “Customer” as the pattern (filter).

11. Choose Transaction as the type object to filter.

12. Select the CustomerID and CustomerName attributes and click OK.

Figure 85 Attribute/Variable Selector window

13. In the Arrange Columns window click OK .

14. Click outside the grid area to unselect it.

Figure 86 Arrange Columns window

Page 92

Getting Started With GeneXus 9.0

15. Click on the Show Borders button of the Formatting Toolbar in order to see the grid borders.

Figure 87 Web Panel Form, with grid

Page 93

Getting Started With GeneXus 9.0

16. Right-click on the Grid and select Properties .

17. Set the AllowSelection property to True and click OK . This will allow you to select customers from the grid just by clicking on them.

18. Click outside the grid area to unselect it and press Enter once.

Figure 88 Grid Properties window

19. On the Insert menu select Table .

20. The Insert Table window will appear. Create a table with 1 row and 4 columns with no caption.

Figure 89 Insert Table window

Page 94

Getting Started With GeneXus 9.0

21. Resize the table by dragging the table corner points with your mouse.

Figure 90 Web Panel Form, with grid and table

22. On the View menu, select Toolbars / Palette .

23. Place the cursor in the first Figure 91 Palette (Controls) Toolbar – Button icon column of the table, and then press on the Button icon in the Palette (Controls) Toolbar.

Page 95

Getting Started With GeneXus 9.0

24. Right-click on the button and select Properties . The button HTML Properties window will appear.

25. Click on the ellipsis (…) of the OnClickEvent property.

Figure 92 Button HTML Properties

26. Click on the New button.

Figure 93 Select Event

27. Write Add (a customer instance) and click OK .

28. Click OK .

29. Click OK . Figure 94 Define User Event

Page 96

Getting Started With GeneXus 9.0

30. Repeat the previous steps to create the Display , Update , and Delete buttons and events. The Web Panel Form like this.

31. Click on the Events tab of the Web Panel.

Figure 95 Web Panel Form, with buttons

Page 97

Getting Started With GeneXus 9.0

32. In the Add Event, write the following function: call(TCustomer, 'INS',0)

33. In the Display Event, write: call(TCustomer, 'DSP', CustomerID)

34. In the Update Event, write: call(TCustomer, 'UPD', CustomerID)

35. In the Delete Event, write: call(TCustomer, 'DLT', CustomerID) Figure 96 Web Panel Events code

36. Save the Web Panel.

Page 98

Getting Started With GeneXus 9.0

37. Go to the Customer Transaction Rules tab and write the following rule: Parm(&Mode, CustomerID);

This rule defines that the Customer object will take two parameters from now on. The first parameter will be assigned to the local variable &Mode. The second one will be assigned to the Figure 97 Customer Transaction Rules CustomerID attribute, defining a specific instance of the Customer object.

From the Web Panel call functions we know that the first parameter defines the operation (insert, update, delete, or display) that the user wants to execute upon the Customer object. This is called transaction mode and can take the values ‘INS’, ‘UPD’, ‘DLT’, and ‘DSP’, respectively. When a transaction object is called with a certain mode, the user can only execute the operation specified by the mode, i.e. insert, update, or delete a transaction instance.

When the Add button is clicked, the CustomerID Autonumber property ignores the value received in the second parameter.

When you define a Parm rule within an object, you are saying that the object can only be invoked by other objects. Therefore, the Customer object will no longer appear in the Developer Menu.

Step 26: Executing the Web Panel: Work with Customers 1. Specify, generate, compile, and execute the application following Step 14: Step 14: Specifying and Generating your Code  Build Command through Step 16: 2. Step 16: Running your Application.

Page 99

Getting Started With GeneXus 9.0

3. Execute the Work with Customers Web Panel.

Figure 98 Developer Menu, with Web Panel

4. You can now add, display, delete, and upgrade customer instances from the Work with Customers web panel.

Figure 99 Work with Customers

Page 100

Getting Started With GeneXus 9.0

CONGRATULATIONS!

You have successfully created your first application with GeneXus.

Our next step is to show you how to generate your application in another platform.

Multi-platform Development In Step 11: Step 11: Prototyping your Application you were asked to choose between two prototype environments .NET and Java. You chose one of them. Now that you have already generated and executed an application in one of these environments, generating and executing the same application in the alternative environment is as simple as defining a new Prototype or Production model.

The GeneXus Trial version features the GeneXus .NET Generator and GeneXus Java Generator. However, the full version of GeneXus supports all the leading software platforms. See www.genexus.com/technologies for a comprehensive list of supported technologies.

Summary

Hopefully, during this introductory tutorial you were able to experience the key features and benefits of GeneXus. They are:

Knowledge-based Application Design

We started by creating a Knowledge Base and describing the data requirements of our application as a series of business components called Transaction Objects in the Knowledge Base Design Model. GeneXus used this input to infer the optimal data model (3rd normal form) needed to support all your Transactions. Also, we added some business rules that GeneXus used to generate the application’s business logic code.

Automatic Database Generation

We chose a specific execution platform (GUI or Web, programming language, DBMS, etc.) and created a Prototype Model where GeneXus automatically generated a new database schema based on the Design Model data model.

Page 101

Getting Started With GeneXus 9.0

Automatic Code Generation and Fully Functional Prototyping

We generated the source code for our application programs and tested the application in the prototype environment.

Application Maintenance

We saw how easy it is to maintain/expand an application just by editing the existing GeneXus objects and/or adding new ones, refactoring the existing database, and regenerating the application programs.

Non-Interactive Process Design

We provided an overview on how to create reports and procedures independently from the application’s database structure.

Multi-platform Development Finally, we saw how easy it is to migrate your GeneXus application from one prototype or production environment to another.

Page 102

Getting Started With GeneXus 9.0

Contact and Resources

GeneXus Community The GeneXus Community provides a variety of ways to get answers to your questions, solutions to your problems, and opportunities to share your own expertise. Find a comprehensive list of Community resources available at http://www.genexus.com/community/

Support Artech offers a wide range of support services and resources:

• Self-Service Online Support These resources are available to anyone online. However, the information that you access depends on your GXtechnical Access Level (Registered User or Customer).

• Interactive Support Services Interact with other members of the Community and with our Support Team.

Visit http://www.genexus.com/support/

If you are located in the USA or Canada you may submit your support questions to [email protected]

How to Buy The GeneXus Technologies are sold through a network of distributors worldwide.

Find a distributor near you at http://www.genexus.com/distributors

Or contact [email protected]

Page 103

Getting Started With GeneXus 9.0

Appendix I: GeneXus Models

Page 104

Getting Started With GeneXus 9.0

Note:

• This is a simplified diagram; there are other ways to go from the Design to a Prototype or Production model: o Build / Impact Objects : triggers a model update that compares the objects in the Design model with the objects in the current model, a Prototype or Production model. o Build / Impact Database : triggers an impact analysis and a model update. • In addition, the Build / Impact From command enable you to trigger an impact analysis and model update from another Prototype or Production Model.

Page 105