K2BTools Tutorial - Exercise 2.5: Using K2BTools Collection Variables

In this exercise we are going to learn how to use K2BTools Collection Variables by making a simple example using product Trn Form.

Since we haven't applied this pattern to product, we will start this exercise by doing it and customizing the Trn Form:

  1. Open "Product" transaction and go to "Trn Form" pattern.
  2. Click on "Apply this pattern on save" checkbox.
  3. Delete all attributes except from "ProductId", "ProductDescription", "ProductType", "ProductPrice", "ProductDetailedDescription" , "BrandId" and "BrandName".
  4. Save your changes in order to apply the pattern.

Collection Variables

Now that product Trn Form is applied, it's time to create a few examples using collection variables.

In these cases we are going to replace "Units" and "Categories" SubWorkWiths with collection variables, showing an alternative way to manage this relations integrated in the main transaction, using collection variables. We believe that this improves the UX of the transaction.

In order to load these variables data, we are going to use dataproviders included in the initial XPZ, while to update the information of the database we are going to use procedures.

  1. Open "Product" transaction and go to "Trn Form" pattern.
  2. Add a new Variable with name "Units2" with the following properties:
    • BasedOn: UnitId
    • Description: Units
    • Is Collection: True
  3. Add a "ControlInfo" to "Units2" with the following properties:
    • Control Type: Suggest K2BTools
    • Data Source From: DataProvider
    • Data Provider: DPUnitsSuggest
  4. Add a new Variable with name "Categories2" with the following properties:
    • BasedOn: CategoryCode
    • Description: Categories
    • Is Collection: True
  5. Add a new "ControlInfo" to "Categories2" with the following properties:
    • Control Type: Dynamic Combo K2BTools
    • Data Source From: DataProvider
    • Data Provider: GetCategories
    • Item Value: CategoryCode
    • Item Description: CategoryName
    • Item Images: CategoryImage
  6. Add the following code inside the "Start" event of the product transaction events. Note: Code must be outside of Fixed slots as seen before.
    EventsConllections
    Collection Variables Events

  7. Add the following code inside product transaction rules: Note: Code must be outside of Fixed slots as seen before.
    RulesConllections
    Collection Variables Rules

  8. Go to "Product" entity services pattern and delete "Product Units" and "Product Categories" SubWorkWiths from the Entity Manager.
  9. Build your application (F5) and see the results in runtime by adding a new product with categories and units.