What is the work around?
I was working on making some adjustments to one of the standard reports in Business Central. – Report 104 “Customer – Detail Trial Bal.” After making a copy of the standard code i noticed that my VS Code showed that on of the lines could not compile.
CurrReport.PrintOnlyIfDetail := ExcludeBalanceOnly or (StartBalanceLCY = 0);
The CurrReport.PrintOnlyIfDetail property is typically used if you create a report having a parent dataitem and one or more child data elements.
So typically if you want to create a report that shows all customer ledger entries for one ore more customers you do not want to print anything if the customer does not have any customer ledger entries.
Like in report 104 where they are defined with a data item link.
dataitem("Cust. Ledger Entry"; "Cust. Ledger Entry")
{
DataItemLink = "Customer No." = FIELD("No."), "Posting Date" = FIELD("Date Filter"), "Global Dimension 2 Code" = FIELD("Global Dimension 2 Filter"), "Global Dimension 1 Code" = FIELD("Global Dimension 1 Filter"), "Date Filter" = FIELD("Date Filter");
DataItemTableView = SORTING("Customer No.", "Posting Date");
To avoid printing customer with no details you will typically have some code like this in the OnAfterGetRecord trigger on the customer data item.
trigger OnAfterGetRecord()
begin
if PrintOnlyOnePerPage then
PageGroupNo := PageGroupNo + 1;
StartBalanceLCY := 0;
if CustDateFilter <> '' then begin
if GetRangeMin("Date Filter") <> 0D then begin
SetRange("Date Filter", 0D, GetRangeMin("Date Filter") - 1);
CalcFields("Net Change (LCY)");
StartBalanceLCY := "Net Change (LCY)";
end;
SetFilter("Date Filter", CustDateFilter);
end;
//workAroundNeeded if in cloud
CurrReport.PrintOnlyIfDetail := ExcludeBalanceOnly or (StartBalanceLCY = 0);
CustBalanceLCY := StartBalanceLCY;
//FetchCustomerName
if SingleCustomer then CustNameForReportHeader := Name;
end;
So this is where we get the challenge if we work with Business Central in the cloud because the CurrReport.PrintOnlyIfDetail property is not supported in the cloud.
So the get around this we must use another method available to use. Where we normally would use this method – in the cloud we must use currreport.skip instead.
So if we change the trigger to something like this:
//workAroundNeeded if in cloud
//CurrReport.PrintOnlyIfDetail := ExcludeBalanceOnly or (StartBalanceLCY = 0);
if ExcludeBalanceOnly or (StartBalanceLCY = 0) then CurrReport.Skip();
CustBalanceLCY := StartBalanceLCY;
That will have almost the same effect. I think the difference will be that with the fix we have to do for the cloud we will get a report head printed even if there are no customers being printed on the report.
The documentation from Microsoft have some inconsistencies when it comes to the documentation for this. For the report property it is documented that it will not work in the cloud, but the same is not the case when we look at the documentation for the data item level.
The missing support for this property has been reported as a bug for a while, but it does not look like Microsoft have a fix for it yet. You can follow the bug case registered in Github.
*This post is locked for comments