Unofficial Content
  • This documentation is valid for:

Name
Last Value
Intention
This pattern occurs with entities that have one or more attributes with the following properties:
 
  • the value of the attribute change over time.
  • it's necessary to keep track of the old values.
  • the last value is the most often required, so it's necessary to be easily accessed.
 
Canonical Example
The canonical example is keeping the values of Currencies. It's necessary to store the price history, but the current quotation is the most often required.

Also the Stock quotes follows the same pattern.
 
Implementation
The transactions are:
 
Currency
CurrencyId*
CurrencyName
CurrencyLastDateTime
CurrencyLastValue

CurrencyValue
CurrencyValueDateTime*
CurrencyValueValue


Notes:
 
  • It isn't necessary to use a SurrogateKey in the CurrencyValue transaction because CurrencyValueDateTime is a good PrimaryKey . In case a SurrogateKey is used, it's necessry to control the consistency of the date time (unique, ordered, etc.), so you end up with a more complicated model without any advantage.

This pattern was implemented defining the attribute CurrencyLastValue as a stored attribute in Currency transaction and the values are syncronized by rules (included in CurrencyValue transaction).
Another way of implementation is Calculated, in this case the attribute CurrencyLastValue it will be calculated each time it's needed.

Currency
   Struct
      CurrencyId*
      CurrencyName
      CurrencyLastDateTime
      CurrencyLastValue
   Rules
      noaccept(CurrencyLastDateTime);
      noaccept(CurrencyLastValue);

CurrencyValue
   Struct
      CurrencyId*
      CurrencyName
      CurrencyLastDateTime
      CurrencyLastValue
      CurrencyValueDateTime*
      CurrencyValueValue
   Rules
      CurrencyLastDateTime = CurrencyValueDateTime if CurrencyLastDateTime <= CurrencyValueDateTime; 
      CurrencyLastValue = CurrencyValueValue if CurrencyLastDateTime <= CurrencyValueDateTime; 

      error('Can not delete last value') if Delete and CurrencyLastDateTime = CurrencyValueDateTime;
 
Implementation of Multiple Values Assigment Pattern
For the generation of the default instance file, you must Currency transaction:

CurrencyId*
CurrencyName

Last Value Assigment Pattern Instance File

The Instance File has the following nodes:

LastValueInstance 

  • BaseTransaction - In this case Currency Transaction.
  • AttributesName - Name of the Atributes to be defined in CurrencyValues Transaction

LastValueAttributesName 

  • ValuesConfiguration - Is a numeric domain (LastValueNumeric) for the attribute that represents last value (CurrencyLastValue). Each time you apply Last Value pattern this domain will be consolidated. By default is defined N(10.2).

LastValue.Config

In this file you can configure:

  • Name of the folder for GeneXus objects
  • Name of the generated attributes
  • Error rule text

Generated GeneXus Objects

By default this pattern generates the following Transaction:

  • CurrencyValues - Stores the currency history.

Sample

LastValueSample

<o:p>
Instalation

You must copy the files in LastValue.zip under C:\Program Files\ARTech\Patterns11\Patterns directory.
Next time you execute Pattern this pattern will be available in patterns list.

 


</o:p>
Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant