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

Notifications

Announcements

No record found.

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 112
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
    31,340 Super User 2025 Season 2 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
    112 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
    112 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
    20,275 Super User 2025 Season 2 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
    112 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
    20,275 Super User 2025 Season 2 on at
    Good to hear Chris!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans