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 “Modes” node, set the “After Insert” property to “ReturnToCaller”.
        ModesNode
        Modes Node

      2. From the “WorkWith” node:
        1. In GridColumns delete all attributes from the grid, except for: CustomerId, CustomerFirstName,CustomerLastName, CustomerDNI, CityName, CountryName, CustomerState.
        2. Delete the filter “CustomerBirthDay”.
          LessonCustomerInstance
          Customer Instance

      3. In the “SubWorkWith(Invoices)” node, delete the following attributes: “InvoiceLastLine”, “InvoiceExpirationDate”, “InvoicePaymentReceived”, “InvoiceTax”, “InvoiceDateFormat”.
      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 “WorkWith” node, delete the “nvoiceExpirationDate” 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 - 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).