Control report execution and background processing
Report execution turns the dataset design into a runtime sequence. Placing logic in the trigger that owns its scope keeps filters, record calculations, cleanup, and preview behavior predictable.
Place logic in the report trigger flow
For an interactive run, Business Central initializes the report, gathers request-page values, prepares the report, processes the data items, and finishes the report. The main trigger flow is:
OnInitReportinitializes state before the request page opens.- The request page collects options and table filters.
OnPreReportvalidates final options and prepares report-wide state.- Each data item runs
OnPreDataItem,OnAfterGetRecordfor each selected record, andOnPostDataItem. OnPostReportperforms report-wide cleanup after data processing.
Use OnPreDataItem for filters that depend on request options because Business Central has already applied request filters at this point. Use OnAfterGetRecord for per-record FlowField calculation, lookup, or derived values. Use OnPostReport for cleanup that belongs after successful dataset processing, not for changing records already emitted to the dataset.
Keep reusable calculations in local procedures and call them from the appropriate trigger. This approach makes trigger intent visible and reduces duplicated logic. Methods such as Report.Run, Report.RunModal, Report.SaveAs, and a report variable's Run method support different invocation and output needs. Choose the method according to whether code needs a request page, a modal result, or a saved artifact.
Account for preview instances
The multiple preview experience keeps the request page open so a user can adjust settings and preview again. This experience uses a primary report instance for the request page and a child report instance for each preview. The child instance processes the report and renders the preview.
This instance boundary affects global state. Values that a child instance changes don't flow back to the primary request-page instance. Store persistent settings through supported request-page behavior or another durable mechanism rather than relying on a global variable changed during preview. Also avoid logic that assumes initialization or side effects occur only once across repeated previews.
SaveValues = true on the request page preserves option values for later use. When the report also allows scheduling, saved values support the multiple-preview experience. Test preview, print, send-to-file, and scheduled execution because each path can expose assumptions about UI availability or instance lifetime.
Use processing-only reports for nonvisual work
A processing-only report uses the report data-item pipeline without producing a layout. Set ProcessingOnly = true when the task needs table iteration, request filters, progress, and report triggers, but no rendered output. Examples include recalculating values or applying a controlled batch update.
report 70410 "Update customer classification"
{
ProcessingOnly = true;
UseRequestPage = true;
dataset
{
dataitem(Customer; Customer)
{
RequestFilterFields = "No.", City;
trigger OnAfterGetRecord()
begin
UpdateClassification(Customer);
end;
}
}
}
A processing-only report doesn't make unsafe changes safe. Validate options before processing, restrict the record set, use database writes deliberately, and consider transaction and retry behavior. Don't declare layouts for a processing-only report.
See Report triggers and runtime operations and ProcessingOnly property for current trigger and property details.