I need to use multiples Report.Print() in a code, but business central only prints the last requested print.
Using a dialog.confirm(), a page.runmodal() or a message() between the prints works, but I need the code to run automatically without user input.
Any ideas?
Ex.: Not working, only last one prints
codeunit 90101 Test
{
trigger OnRun()
var
salesInvoice: Record "Sales Invoice Header";
RecRef: RecordRef;
begin
salesInvoice.setfilter("No.", '103021');
RecRef.GetTable(salesInvoice);
Report.Print(1306, '', '', RecRef);
salesInvoice.Reset();
salesInvoice.setfilter("No.", '103022'); //only this one prints
RecRef.GetTable(salesInvoice);
Report.Print(1306, '', '', RecRef);
end;
}
Ex2.: working, prints both
codeunit 90101 Test
{
trigger OnRun()
var
salesInvoice: Record "Sales Invoice Header";
RecRef: RecordRef;
begin
salesInvoice.setfilter("No.", '103021');
RecRef.GetTable(salesInvoice);
Report.Print(1306, '', '', RecRef);
salesInvoice.Reset();
salesInvoice.setfilter("No.", '103022');
RecRef.GetTable(salesInvoice);
if Dialog.Confirm('hello') then;
Report.Print(1306, '', '', RecRef);
end;
}
I'm having the same issue. I was just as confused as I kept thinking "but how does report selection work then?" but realized it always opens the request page.
I'm considering these 2 options:
This is worked out quite well for me: