Hello. I have a fairly simple custom report that I’ve created in AL Code. The report works, and prints/previews correctly.
But I want to save the output to a .docx files not print it. I don’t want users to have to click on Send To on the request page, although that it my fallback option if this isn’t possible. Ideally I don’t want the option to Print, Preview or Send To, but download report as a .docx.
I was hoping to make use of something along the lines of this, and it works (it downloads a docx with the right filename and the report layout) but it doesn’t run the report request page to choose the options so it always defaults to the ‘first’ job.
ReportParameters := Report.RunRequestPage(50103);
TempBlob.CreateOutStream(OStream);
Report.SaveAs(50103, ReportParameters, ReportFormat::Word, OStream);
FileManagement.BLOBExport(TempBlob, Format(Job."No.") + '_' + 'Report' + '_' + Format(CURRENTDATETIME, 0, '<Day,2><Month,2><Year4>') + '.docx', true);
Any ideas? My current report is (with some details removed for brevity):
report 50103 "Customer Report"
{
Caption = 'Customer Report';
UsageCategory = Documents;
ApplicationArea = All;
DefaultRenderingLayout = CustomerReport;
Description = 'Produces a customer job card';
PreviewMode = PrintLayout;
dataset
{
dataitem(Job; Job)
{
RequestFilterFields = "No.";
column(No_; "No.")
{ }
}
}
rendering
{
layout(CustomerReport)
{
Type = Word;
LayoutFile = 'CustomerReport.docx';
}
}
}
My action (on the Job card) is currently thus:
trigger OnAction()
var
Job: Record Job;
CustomerReport: Report "Customer Report";
begin
Job.SetFilter("No.", Rec."No.");
CustomerReport.SetTableView(Job);
CustomerReport.RunModal();
end;
We are running Business Central 22.2 SaaS (online/cloud).
I look forward to any advice and assistance…