web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Set Report layout for Posted Sales Invoice based on value in Customer-Record

(2) ShareShare
ReportReport
Posted on by 114
Hello Community! 

I have a report with 3 layouts for the posted sales invoice. Layout#1 came with an app. Layout#2 and Layout#3 have been added in the report-extension I'm working on.
The default is Layout#2.
If a certain value in the bill-to-customer is set, the selected layout in the request page should be layout#3.

Sounded pretty simple, but so far no solution completely worked.

Yun Zhu already wrote about a pretty similar case here: How to set the default report layout via AL (“Report Layout List 2000000234” and here: How to specify the report layout before printing via AL (“Report Layout List 2000000234” not “Custom Report Layout 9650”).
His solution is for Sales Invoice and obviously modifiying the value for a new field in the Posted Sales Invoice doesn't work. Still there are some good suggestions in those articles. But here's why they didn't work for me:

Reason 1: PrintDocumentWithCheckDialogCommon

This is a local procedure in the ReportSelections-table. It's called during the standard process and it cleares the Design-Time-Report-Selection. So it's useless setting this value on the OnBeforeAction-Trigger of the Print-Button. 

Reason 2: Report xxx "does not have a valid layout"
 
So I tried different approaches:
Approach A: Use an event that is called after the PrintDocumentWithCheckDialogCommon-procedure and set the Design-Time-Report-Selection (e.g. OnAfterSubstituteReport). 
Approach B: Set the ReportLayoutSelection-Value on the OnBeforeAction-Trigger of the Print-Button.
Approach C: Set the ReportSelections."Report Layout Name" on the OnBeforeAction-Trigger of the Print-Button. This way the PrintDocumentWithCheckDialogCommon-procedure replaces the ReportLayoutSelection-Value later.

All those approaches somehow worked. At least the request-page was opened and the correct layout was selected. BUT if you click Preview or Print there is an error-Message stating that the report "does not have a valid layout". If you manually select the very same layout on the request page it works fine. This error message seems to be caused by the OnInitReport-Event (which is not available in Report-extensions) right when it's called. 

So I don't have any further ideas. Is the error message supposed to be like this?
Does anyone have an idea how to make this work?

Thanks in advance! Christopher
I have the same question (0)
  • Suggested answer
    Valentin Castravet Profile Picture
    32,796 Super User 2026 Season 1 on at
    If nothing works then another thing you can do is simply add a different action button for each layout. 
     
     
  • Chris Brill Profile Picture
    114 on at
    Hello Valentin, 

    thanks for your reply. I've considered this as well, although it might still have the same problems as I have to replace the standard-layout as well. 
    And as the user doesn't always know whether the decisive value is set, I would have work with message boxes, to tell the user to use the user button. Not really a nice workflow. 
  • Chris Brill Profile Picture
    114 on at
    Does nobody know, if this is a bug in BC, or by what this is caused and if there is a walkaround? :-/ 
  • Verified answer
    Khushbu Rajvi. Profile Picture
    22,752 Super User 2026 Season 1 on at
    Simmilar issue: Report id does not have a valid layout. Valid layout types are: Word, RDLC, Excel, and Custom.
    https://community.dynamics.com/forums/thread/details/?threadid=d055386e-3b18-ef11-9f8a-6045bddbf119
     
    Hope this helps
  • Verified answer
    Chris Brill Profile Picture
    114 on at
    Thanks a lot, 
    the thread didn't help, but the answer to the GitHub-issue did solve my problem. 

    When I used 
    DesigntimeReportSelection.SetSelectedLayout('ReportName');

    I didn't use the name, but the caption. So I did see the correct caption, but there was no report linked to it. I  expected BC to check this in the procedure, but it obviously doesnt.

    By the way: 

    ReportLayoutSelection.SetTempLayoutSelectedName('ReportName');
     
    works as well.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    22,752 Super User 2026 Season 1 on at
    Good to hear Chris!
  • KM-25111559-0 Profile Picture
    21 on at
    pageextension 50108 contractsPostedSalesInv extends "Posted Sales Invoice"
    {
        actions
        {
            addlast(processing)
            {
                action(printContract)
                {
                    ApplicationArea = All;
                    Caption = 'Print contract';
                    Image = ContractPayment;
                    trigger OnAction()
                    var
                        DesignTimeReportSelection: codeunit "Design-time Report Selection";
                    begin
                        SalesInvHeader := Rec;
                        CurrPage.SetSelectionFilter(SalesInvHeader);
                        DesignTimeReportSelection.SetSelectedLayout('CONTRACT');
                        report.RunModal(1306, true, false, SalesInvHeader);
                    end;
                }
            }
        }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,386 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,774 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,515

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans