Writing /giga/dw/dng/dokuwiki/data/meta/dev/010how/100sys/0075tngasch2.meta failed
dev:010how:100sys:0075tngasch2

Check rules and database access

Check rules are not allowed to change any transaction field or modules and can work only with local variables. Thus if it is needed to read database entries in check rules it is not possible to use standard database access functions as e.g. dbread.

The only option is to access the data by DbExecuteSql(var) and manually assign and use register fields locally in the checkrule.

To escape from this a typical implementation is to fill a module in a default rule and use the fields loaded that way in the check rule.

The negative performance effect of this is

  1. The Default is executed on startup of the transaction causing a delayed startup
  2. The Default is executed too often, as only after changing of the relevant fields a database access is necessary

A different implementation is to define a separate module instance with the module property static which places this module instance outside the TradeDesign flow. Thus nothing depends on this module instance. A checkrule might fill this instance and utilize the loaded data within the context of the checkrule to issue error messages including references or names of the originating dataset.

To flag the special instance those instances should be prefixed by CHK followed by the table / class name.

When utilizing a cached database access, the performance will be pretty high, as the data is loaded only once, when the field is left or the Check / Save Button is pressed and not when loading the transaction.

Implementing the additional module instance has the cost of additional data and potentially multiple loading of the same data in case multiple check rules will check the same dataset.

Sample

Assuming that in the current transaction and module structure there is an instance PTAMAA which holds a field ANTID to be checked for a unique usage.

  • Add module instance CHKPTA
  • Flag that module as static module
  • Add an instance comment clarifying that that instance is static and intended for Check rule usage
Check PTAMAA\ANTID
if not isempty( PTAMAA\ANTID ) then
  $Sql = FormatText( SdbEtyGenSql( CHKPTA, “where ANTID = $1 and INR <> $2” ), SqlLit( PTAMAA\ANTID ), 
  SqlLit( PTAMAA\PTAINR ) )
  CacheDbReadSql ( CHKPTA, $Sql )
  If Errorcode <= 0 then
    Error( ‘The allNETT Id $1 is already used with $2 / $3 and cannot be assigned to this customer.\n
    If needed first change the data of customer $4.’, PTAMAA\ANTID, CHKPTA\EXTKEY, CHKPTA\NAM, CHKPTA\EXTKEY )
  Else
    If Errorcode <> TdOdbcNotFound then
      Reraise
    Endif
  Endif
Endif
dev/010how/100sys/0075tngasch2.txt · Last modified: 2024/04/05 10:10 (external edit)