Anveo Web Portal / Installation / Business Logic in Tables

Business Logic in Tables

Due to the technical structure of publishing tables via Anveo Pages it is necessary that the entire business logic is located within tables and codeunits – not in forms/pages. Viewed conceptually, this is cleaner from the very start because a table has to check itself for structural consistencies, because codeunits are envisaged for working with business processes, and because forms/pages merely represent input/output involving the application user.

As a result, when publishing a table it is to be checked whether calculations or tests are located in the counterpart – the form/page in Client – which are to be shifted into the table.

xRec and CurrFieldNo

xRec is used in numerous table functions within and represents the record prior to a modification. xRec can be used in an OnValidate trigger to test whether a field has actually changed, for example in the OnValidate trigger for the Customer table.

IF "No." <> xRec."No." THEN BEGIN
SalesSetup.GET;
NoSeriesMgt.TestManual(SalesSetup."Customer Nos.");
"No. Series" := '';
END;
IF "Invoice Disc. Code" = '' THEN
"Invoice Disc. Code" := "No.";
Source code of OnValidate trigger of field No. within the table Customer

However, xRec is only available when an input takes place via a form/page. The missing xRec in the case of functions within tables and codeunits is a constraint posed by which is not conspicuous when using Client because the data are modified solely via forms and pages there, and those pages offer xRec automatically. Without the xRec, the code shown above will not work properly.

Anveo Client Suite provides the function GetxRec in the codeunit ACF Management so that Anveo Client Suite sets the xRec and CurrFieldNo correctly, too. In the Anveo Client Framework core application there is a template for the GetxRec function and sample code for correct activation. Proceed as shown in the following so that the xRec and CurrFieldNo are available to you for your tables:

  • Create in your table the function GetxRec with following parameters:
  • Add to the function GetxRec the following code:
ACFxRec.GETTABLE(xRec);
ACFManagement.GetxRec(ACFxRec,CurrFieldNo);
IF ACFxRec.NUMBER <> 0 THEN
   ACFxRec.SETTABLE(xRec);
  • Add the following code at the beginning of all table triggers which use the xRec or CurrFieldNo:
//+Anveo Client Suite Integration
GetxRec(xRec,CurrFieldNo);
//-Anveo Client Suite Integration

The execution of the code is compatible with the Classic, Role Tailored Client and Windows client of Microsoft Dynamics NAV. Since the code runs on all clients, no separate case distinction is necessary. Calling this function can be performed by each table in the system as often, only the first call using the Anveo Client Suite returns correspondingly xRec and CurrFieldNo.