Business Requirement
With the DataField Property of a section group control on a report, you can create sections using the same table. In this post I explain how you can turn this off if the DataField Property has a value in your Report Design.
This post uses an existing Report as example: Report CustGrossMarginByAccount. It can be found in Accounts Receivable > Reports > Statistics > Customer > Gross Margin by Customer.
Solution
Step 1 Add new global variables in the ClassDeclaration
Add new global variables dialogShowSubTotals and showSubTotals in the ClassDeclaration of Report CustGrossMarginByAccount: a new checkbox should become available on the startup dialog of the Report in which the end user can choose to print subtotals or not.
public class ReportRun extends ObjectRun
{
Amount custGross;
Amount custMargin;
Amount custCost;
Amount totGross;
Amount totMargin;
ReportSectionGroup rsSG;
ReportSection rsBody;
ReportSection rsDetailHeader;
ReportSection rsSummaryHeader;
CustName custName;
DialogField dialogSummary;
NoYes summary;
DialogField dialogShowSubTotals;
NoYes showSubTotals;
#define.CurrentVersion(2)
#localmacro.CurrentList
summary,
showSubTotals
#endmacro
}
Step 2 Add a field to the dialog to have the option to print subtotals
Add a field to the dialog by modifying the dialog method: the user will be able to choose here if subtotals should be printed or not.
public Object dialog(Object _dialog)
{
DialogRunbase dialog = super(_dialog);
;
dialog.addGroup("@SYS7764"); // Parameters
dialogSummary = dialog.addFieldValue(typeid(NoYes),
summary,
"@SYS62602",
"@SYS99221");
dialogShowSubTotals = dialog.addFieldValue(typeid(NoYes),
showSubTotals,
"@SYS26674");
return dialog;
}
Step 3 Store the value by modifying the getFromDialog method
Modify the getFromDialog method to store the value of the chosen print option.
public NoYes getFromDialog()
{
;
summary = dialogSummary.value();
showSubTotals = dialogShowSubTotals.value();
return true;
}
Step 4 Modify the fetch method to turn subtotals on or off
Modify the fetch method to switch the subtotals on or off.
public boolean fetch()
{
Queryrun qr;
ReportSectionGroup reportSectionGroup;
;
if (!showSubTotals)
{
reportSectionGroup = element.design().sectionGroup( tableNum(CustInvoiceJour)
,fieldName2Id(tableNum(CustInvoiceJour)
,"OrderAccount"));
reportSectionGroup.dataField(0);
} …..
}
Result
Upon starting the Report CustGrossMarginByAccount the end user has the option to print the subtotals per Order Account or not.
Leaving the option unchecked, results in a report without subtotals per Order Account:
Checking the subtotals option results in a report with the subtotals:
Continue reading......