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