How to fill temporary tables in AL-code and use them in custom layouts

In the ForNAV Designer, you can add new data items to a layout without modifying the underlying AL-code. This has the benefit of easy deployment and maintenance, because the changes only exist in custom layout, which is data and not code.

Data items require temporary tables to run and custom AL-logic to fill up the table. You can do this in the ForNAV Designer by adding a new data item to a custom layout:

 

When the report runs, the OnForNAVFillTemporaryTable event is called (just before OnPreDataItem) to fill up the table and the data item executes like any normal data item.

The OnForNAVFillTemporaryTable event has the following parameters:

  • ReportID – the number of the report.
  • ChildDataItemId  – the name of the virtual data item.
  • ParentRecRef – a RecordRef to the parent (or sibling) data item.
  • TempRefRec – a RecordRef to the temporary table to fill.
  • IsHandled – set to true to disable normal ForNAV behavior.

 

The following example fills a VAT Amount Line temporary table with the VAT specification from the Header, which is the parent data item:

[EventSubscriber(ObjectType::CodeUnit, Codeunit::"ForNAV TempTable",
    'OnForNAVFillTemporaryTable', '', false, false)]
local procedure OnForNAVFillTemporaryTable(ReportID: Integer;
    ChildDataItemId: Text; ParentRecRef: RecordRef;
    var TempRecRef: RecordRef ; var IsHandled: Boolean)
var
    VATAmountLine: Record "VAT Amount Line" temporary;
    TestValidDociFace: Codeunit "ForNAV Test Valid Doc iFace";
    DocLineBuffer: Record "ForNAV Document Line Buffer" temporary;
    LineRec: RecordRef;
begin
    if TempRecRef.Number = Database::"VAT Amount Line" then begin
        if TestValidDociFace.CheckValid(ParentRecRef) then begin
            FindLinesRecRef(DocLineBuffer, ParentRecRef, LineRec);
            TempRecRef.SetTable(VATAmountLine);
            CreateVATAmountLine(DocLineBuffer, VATAmountLine);
            TempRecRef.Copy(VATAmountLine, true);
        end;
    end;
end;

Out of the box, the ForNAV Customizable Report Pack comes with event subscribers to create:

  • Assembly Line
  • Bank Account information from currency code
  • Item Attribute Value Selection
  • Tracking Specification
  • Payment Service Setup
  • Sales Tax Buffer
  • VAT Amount Line
  • Aggregated General Ledger Entries
  • Aggregated Customer Ledger Entries
  • Aggregated Vendor Ledger Entries
  • Aggregated Item Ledger Entries
  • Aggregated Value Entries
  • Repeater Line

A prerequisite is that ForNAV 6.2.0.2226 and the Customizable Report Pack 6.2.0.5 or later is installed.