Skip to content

Extended Functionality in Report Printing - OnReportPost

Introduction

The enhanced functionality of the revamped OnReportPost function offers increased flexibility while handling report printouts. The new feature allows users to archive reports to another data record. This article provides an overview of the new functionality and its application.

The Overloaded OnReportPost Function

AL
procedure OnReportPostDataItem(ParamRRecordRef: RecordRef; ParamReportNoInteger: Integer; ParamReportPreviewBoolean: Boolean; ParamSaveToRecordRef: RecordRef) ReturnEntryNoBigInteger: BigInteger
    var
        LocalRecordSIMDMSReportSetup: Record "SIM_DMS Report Setup";
        LocalR2RecordRef: RecordRef;
        LocalFFieldRef: FieldRef;
        LocalF2FieldRef: FieldRef;
        LocalKKeyRef: KeyRef;
        LocaliInteger: Integer;
    begin
        if GlobalCodeunitSIMDMSSI.GetDisableShadowPrint() then exit;
        if GlobalCodeunitSIMDMSSI.GetIsEmailBodySending() then exit;

        if ParamRRecordRef.Number() = 0 then exit;
        if not LocalRecordSIMDMSReportSetup.Get(ParamReportNoInteger) then exit;

        if (not ParamReportPreviewBoolean) and (not GlobalCodeunitSIMDMSSI.GetPdfPrint() and GuiAllowed()) then
            if ParamRRecordRef.FindSet() then
                repeat
                    LocalR2RecordRef.Open(ParamRRecordRef.Number());
                    LocalKKeyRef := ParamRRecordRef.KeyIndex(1);
                    for LocaliInteger := 1 to LocalKKeyRef.FieldCount() do begin
                        LocalFFieldRef := LocalKKeyRef.FieldIndex(LocaliInteger);
                        LocalF2FieldRef := LocalR2RecordRef.Field(LocalFFieldRef.Number());
                        LocalF2FieldRef.SetRange(LocalFFieldRef.Value());
                    end;
                    LocalR2RecordRef.FindFirst();

                    ReturnEntryNoBigInteger := SaveRelation(LocalR2RecordRef, ParamReportNoInteger, true, false, ParamSaveToRecordRef);

                    LocalR2RecordRef.Close();
                until ParamRRecordRef.Next() = 0;
    end;

Description of the Code

The procedure 'OnReportPostDataItem' takes several parameters, including 'ParamRRecordRef' and 'ParamSaveToRecordRef'. The code first checks whether the shadow or PDF print functions are deactivated. If activated, it copies the relevant data from the source data record reference to the target data record reference. The 'SaveRelation' function is called to establish the relationship between the data sets and return the result.

Application Example

This function is particularly useful if a report is to be created from a source table and archived in another table. For example, a report based on table A can be moved using the OnReportPost function so that it is linked to table B.

Advantages

Increased flexibility: Users can upload reports to different data sets, resulting in more flexible data management. Improved user experience: The feature was developed in response to user feedback to improve the overall user experience. Efficiency: The ability to attach reports specifically to different datasets increases the efficiency and accuracy of data management.