Activate new Layout with Report Extensions

Activate new Layout with Report Extensions

Introduction

In times of C/AL, changes to the layout of RDL reports took effect automatically when the report objects were imported into the database. This is no longer the case with AL and Report Extensions. After publishing the app, the new layout must first be selected and assigned in the report layout selection manually.

This can (and should in my opinion) be automated. My solution for handling and automate this process looks like this:

Solution

In the report extension rendering area, I specify a layout name with a prefix and a fixed text. This way, the layout can later be uniquely referenced together with the standard report ID, which is extended.

Code Example:

reportextension 50000 "SOM Vend. Pre-Paym. Journal" extends "Vendor Pre-Payment Journal"
{

    dataset
    {
        add("Gen. Journal Line")
        {
            column(SOM_GenJnlLine_ExtDocNo_Caption; FieldCaption("External Document No."))
            {
            }
            column(SOM_GenJnlLine_ExtDocNo; "External Document No.")
            {
            }
        }
    }
    rendering
    {
        layout("SOM RdlLayout")
        {
            Type = RDLC;
            LayoutFile = './Src/Layout/VendorPrePaymentJournal.rdl';
            Caption = 'Vendor Prepayment Journal';
        }
    }
}

To activate the layout from the report extension, I then use a function that sets the standard layout for a specific report ID in the Table “Tenant Report Layout Selection”. Since the report selection is per comany, the method can either be executed for the current company or for all companies of the tenant.

Code Example:

procedure UpdateAllReportExtLayouts(AllCompanies: Boolean)
begin
    SetReportExtLayoutAsStandardLayout(Report::"Vendor Pre-Payment Journal", AllCompanies);
end;

local procedure SetReportExtLayoutAsStandardLayout(ReportID: Integer; AllCompanies: Boolean)
var
    ReportLayoutList: Record "Report Layout List";
    TenantReportLayoutSelection: Record "Tenant Report Layout Selection";
    Company: Record Company;
    EmptyGuid: Guid;
    myAppInfo: ModuleInfo;
begin
    NavApp.GetCurrentModuleInfo(myAppInfo);
    ReportLayoutList.SetRange("Report ID", ReportID);
    ReportLayoutList.SetRange(Name, 'SOM RdlLayout');
    if ReportLayoutList.FindFirst() then begin
        if not AllCompanies then
            Company.SetRange(Name, CompanyName());
        if Company.FindSet() then
            repeat
                TenantReportLayoutSelection.ChangeCompany(Company.Name);
                TenantReportLayoutSelection."App ID" := ReportLayoutList."Application ID";
                TenantReportLayoutSelection."Company Name" := Company.Name;
                TenantReportLayoutSelection."Layout Name" := ReportLayoutList.Name;
                TenantReportLayoutSelection."Report ID" := ReportLayoutList."Report ID";
                TenantReportLayoutSelection."User ID" := EmptyGuid;
                if not TenantReportLayoutSelection.Insert(true) then
                    TenantReportLayoutSelection.Modify(true);
            until Company.Next() = 0;
    end;
end;

The method can be called in the OnInstallAppPerCompany trigger, for example.
Hope it helps, have fun!

0 comments on “Activate new Layout with Report ExtensionsAdd yours →

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.