Real-World Example of Processing-Only Reports in Business Central: Block Inactive Customers
In our previous blog, we explored what Processing-Only Reports are in Microsoft Dynamics 365 Business Central — how they work, when to use them, and their benefits over codeunits.
In this post, we’ll take it a step further by walking through a real-world use case: a report that automatically blocks inactive customers who haven’t had any sales activity in the past year.
Goal: Identify customers with no posted sales invoices in the last 12 months and automatically block them from making new transactions.
Since this task doesn’t require any printed output — only data processing — it’s a perfect use case for a Processing-Only Report.
report 50134 BlockInactiveCustomers
{
Caption = 'Block Inactive Customers';
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
ProcessingOnly = true;
dataset
{
dataitem(Customer; Customer)
{
trigger OnAfterGetRecord()
var
SalesInvHeader: Record "Sales Invoice Header";
OneYearAgo: Date;
begin
OneYearAgo := CalcDate('-1Y', Today);
SalesInvHeader.Reset();
SalesInvHeader.SetRange("Bill-to Customer No.", Customer."No.");
SalesInvHeader.SetFilter("Posting Date", '>%1', OneYearAgo);
if not SalesInvHeader.FindFirst() then begin
Customer.Blocked := Customer.Blocked::"All";
Customer.Modify();
BlockedCount += 1;
end;
end;
}
}
trigger OnInitReport()
begin
BlockedCount := 0;
end;
trigger OnPostReport()
begin
Message('%1 customers were blocked due to inactivity.', BlockedCount);
end;
var
BlockedCount: Integer;
}
Comments
Post a Comment