K2BTools Tutorial - Exercise 2.1: Customizing objects generated with K2BEntityServices

Introduction

In this exercise we will update a transaction where the EntityServices pattern was applied.

1- Instance creation

  1. Apply the EntityServices pattern to the Customer transaction.
    1. Perform these modifications in the instance:
      1. In the "Standard actions" node, set the “After Insert navigation” property to “ReturnToCaller”.
        TutorialAfterInsertProperty1
        After Insert navigation Property

      2. From the “WorkWith” node:
        1. In GridColumns delete all attributes from the grid, except for: CustomerId, CustomerName, CustomerNumber, CityName, CountryName, CustomerStatus.
        2. Delete all filters except for “CustomerName".
          LessonCustomerInstance10
          Customer Instance

      3. In the “SubWorkWith(Invoices)” node, delete all attributes except from: “InvoiceCode”, “InvoiceDate” and “InvoiceTotal".
      4. In the “SubWorkWith(Invoices)” node, delete the filter: “InvoiceExpirationDate”.
  2. Apply the EntityServices pattern to the Invoice transaction.
    1. Perform these modifications in the instance:
      1. In the “WorkWith” node, delete these attributes: “InvoiceLastLine”, “InvoiceExpirationDate”, “InvoicePaymentReceived”, “InvoiceTax”, “InvoiceDateFormat”.
      2. In the “Filters” node, delete the “InvoiceExpirationDate” filter.
  3. Generate and run the application to see the result.
  4. Create a Customer and an Invoice to see how the interfaces work by default.

2 - Editing the pattern instance

When using patterns, two options are available: The first one is to edit the pattern instance inside the transaction and the other option is to edit the Pattern object directly, by opening the object in the Folder View.

TutorialPatternObject1
Pattern object in the folder view

Opening this object you can edit the pattern instance directly.

EntityServInstance
Entity Services Instance

The advantage of the second option is that the pattern is not applied each time it is saved, it is automatically applied before generating the application instead. If you need to force the application of the pattern before that, you can use the “Apply Pattern” action, as seen below.

TutorialApplyPatternAction1
Apply Pattern Action

3 - Update rules and events

K2BEntityServices updates the definition of the transaction it is applied on. In order to do so, it uses code slots. Slots are sections of GeneXus code delimited by comments. They start with a comment of the form “//+ <owner>.<functionality><.Fixed>” and end with a comment “//-”. You can see more details in Code slots in Rules and Events, in this exercise we will learn how these slots work in a practical manner.

Adding code outside slots

  1. Open the Invoice transaction, and enter its “Rules” part.
  2. At the bottom (outside all slots) place the following rule: "serial(InvoiceLineId, InvoiceLastLine, 1);"
  3. Save the transaction. You can verify that the rule is not modified.

Adding code inside “Fixed” slots

  1. Open the Customer transaction, and enter its “Rules” part.
  2. Locate a “Fixed” slot. To do this, look for the postfix “.Fixed” in the slot’s name.
  3. Add a comment such as “// I’m inside the Fixed slot” to the slot.
  4. Save the transaction. You can verify that K2BTools deleted the comment you just added.

Adding code inside “Non-Fixed” slots

  1. Open the Customer transaction, and enter its “Rules” part.
  2. Locate a “Non-Fixed” slot. To do this, look for a slot without the “.Fixed” postfix as in the following example:
  3. Add a comment such as “// I’m inside a non-fixed slot”.
  4. Save the transaction. You can verify that K2BTools did not delete the comment you just added.

Summing up

In this exercise, we have seen that the following rules must be followed by the developer:

  1. The developer can add code outside the slots.
  2. The developer can add or update code in “Non-Fixed slots”.
  3. The developer can NOT add add code in “Fixed slots” (as they will be deleted).