Dynamics 365 Business Central: How to specify the report layout before printing via AL (“Report Layout List 2000000234” not “Custom Report Layout 9650”)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to specify the report layout (“Report Layout List 2000000234”) before printing in AL. A few days ago, a partner asked me an interesting question, the customer wants to print different report layouts according to different conditions in the sales order, but the report is the same. Is there a way to deal with it?

Okay, as you might know, Microsoft has released the following feature in Business Central 2022 wave 2 (BC21), users can choose which report layout to use on the request page. More details: Business Central 2022 wave 2 (BC21) new features: Choose the report layout on request page (Select a report layout before printing)

Report Layouts (9660, List) and Report Layout List (2000000234)

This is a great feature, but this is a manual selection by the user and there may be mistakes. And customers need to make frequent selections😑, so that’s why automation is needed.

Before the release of the new feature above, we have discussed Dynamics 365 Business Central: Select a report layout before printing.

Key method: ReportLayoutSelection.SetTempLayoutSelected(Code)

The Code is the primary key in table 9650 “Custom Report Layout”.

But that is for “Custom Report Layout 9650”, not Report Layout List (2000000234). For example, the standard layouts aren’t included.

Regarding the method of creating and modifying Custom Report Layouts, it is moving from
Report Layout Selection (9652, List) to Report Layouts (9660, List).

More details: New pages for report layout administration (page 9660 “Report Layouts”)

PS:
1. (Legacy) Create and Modify Custom Report Layouts:

Custom report layouts is a legacy feature that is being phased out. Instead, you should start creating user-defined layouts as described here.

2. Setting the Layout Used by a Report:

You can’t use the Report Layouts page for Word and RDLC layouts that were created by using the legacy Custom Layouts feature. In fact, you won’t even see these custom layouts listed on the Report Layouts page. For these layouts, you can only set them by using Report Layout Selection page.

So we have to change our practices.
First of all, the Report Layouts app is not included in the base application, you need to add a dependencies setting in app.json file to download the symbol file.
ReportLayouts:

  "dependencies": [
    {
      "id": "b7174aae-753c-4e71-bacb-d973995dce5e",
      "name": "_Exclude_ReportLayouts",
      "publisher": "Microsoft",
      "version": "22.0.0.0"
    }
  ]

Standard objects in ReportLayouts:

Then we can find some clues in codeunit 9660 “Report Layouts Impl.”.

codeunit 9654 “Design-time Report Selection”: procedure SetSelectedLayout

To make it easier to understand, let me make a simple example.

Before opening the Request Page of the report, the user can specify the report layout on the order, and the layout selected on the order will be applied when the report is opened.

Test video:

It looks simple, right? Of course, you can change the solution, for example to print another layout when the currency is foreign. Give it a try!!!😁

Source Code: Please note that the source code is for reference only, you can improve it according to your own needs

tableextension 50111 SalesHeaderExt extends "Sales Header"
{
    fields
    {
        field(50100; "Report Name"; Text[250])
        {
            DataClassification = CustomerContent;
            Caption = 'Report Name';

            trigger OnLookup()
            var
                ReportLayoutList: Record "Report Layout List";
            begin
                ReportLayoutList.Reset();
                ReportLayoutList.SetRange("Report ID", 1305);
                if Page.RunModal(Page::"Report Layouts", ReportLayoutList) = Action::LookupOK then
                    Rec."Report Name" := ReportLayoutList.Caption;
            end;
        }
    }
}

pageextension 50112 SalesOrderExt extends "Sales Order"
{
    layout
    {
        addafter("Sell-to Customer Name")
        {
            field("Report Name"; Rec."Report Name")
            {
                ApplicationArea = All;
                Caption = 'Report Name';
            }
        }
    }

    actions
    {
        modify("Print Confirmation")
        {
            trigger OnBeforeAction()
            var
                DesigntimeReportSelection: Codeunit "Design-time Report Selection";
            begin
                if Rec."Report Name" <> '' then
                    DesigntimeReportSelection.SetSelectedLayout(Rec."Report Name");
            end;
        }
    }
}

Update: How to set the default report layout via AL (“Report Layout List 2000000234”)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL