K2BTools Tutorial - Exercise 1.1: K2BEntityServices basic usage

Introduction

In this exercise you will learn how to use K2BEntityServices in GeneXus. K2BEntityServices is the main pattern in the K2BTools suite, and generates the base architecture upon which the application is built. Work With interfaces are built using this tool, as well as all interfaces needed to view, update or delete records for the transaction it is applied in.

In this exercise the pattern will be applied to the Country, City, Product, ProductStorage, and ProductUnits transactions. Then the generated application will be executed to see the end result.

Pattern application

1 - Apply the pattern to the Country transaction

  1. Open the “Country” transaction.
  2. Go to “Patterns” part.
    PatternPart
    Pattern Part

  3. Select the option "Create with the default template".
    CreateWithTheDefaultTemplate2
    Create with the default template.

  4. Check the “Apply this pattern on save” option.
    ApplyPatternOnSave
    Apply Pattern On Save

  5. Save the transaction.

Note: The first time a pattern is applied, a set of GeneXus objects, called “Basic Objects” are imported in the KB. This objects are referenced in the generated code, and implement common features. For this reason, the first time a pattern is applied the process takes longer.

  1. Go to the KB Explorer in GeneXus, and find the Country transaction. Now, this transaction should contain the instance as a child object, along with its generated objects.
    PatternGeneratedObjects
    Pattern-generated objects

2 - Apply the pattern to the City transaction

In this case, you will perform some changes to the default configuration.

  1. Open the "City" Transaction
  2. Apply the pattern to the City transaction following the same steps followed in the previous section.
  3. WorkWith Node: Delete this node. After this deletion, cities will be accesible only through the Country Entity Manager.
    WorkWithDelete
    Delete WorkWith

  4. EntityManager Node: Delete the Customer SubWorkWith from this node.
    SubWorkWithDelete
    Delete SubWorkWith

3 - Apply the pattern to the Product transaction

After applying the pattern on this transaction, as seen in the first section, perform these changes.

  1. Delete all attributes except for "ProductId", "ProductDescription", "ProductType and "ProductPrice" from the WorkWith nodes and all filters except for "ProductDescription" filter.
    AttributeDelete1
    Product Attributes

  2. Delete the “Invoices” SubWorkWith from the EntityManager.
  3. Go to "Standard actions" node and set After Insert navigation property to "Return To Caller"
    TutorialAfterInsertProperty1
    After Insert Property

4 - Apply the pattern to the Invoice transaction

After applying the pattern on this transaction, as seen in the first section, perform these changes.

  1. Delete all attributes except from "InvoiceCode", "InvoiceDate", "CustomerName", "CountryName" and "InvoiceTotal".
    AttributeDelete11
    Invoice Attributes

  2. Delete the “Payments” SubWorkWith from the EntityManager.
  3. Go to "Standard actions" node and set After Insert navigation property to "Return To Caller"
    TutorialAfterInsertProperty1
    After Insert Property

5 - Apply the pattern to the ProductStorage transaction

After applying the pattern on this transaction, as seen in the first section, perform these changes.

  1. Delete the WorkWith node.
  2. Delete all Components inside the Entity Manager, except the “General” component. You should delete all the SubWorkWith and Parallel nodes.

6 - Apply the pattern to the ProductUnits transaction

After applying the pattern on this transaction, as seen in the first section, perform these changes:

  1. Delete the WorkWith node.

7 - Apply the pattern to the Unit transaction

Apply the pattern as seen in the first section.

8 - Apply the pattern to the Category transaction

Apply the pattern as seen in the first section.