How to Create a Complex Report Dialog Form
Let’s assume that we need to create the report dialog form for the List of purchase orders report, which looks like as shown on the picture below.
The needed artifacts for each Basic report including the List of purchase orders report are:
- Data Source Provider (DSP) class which provides the report data
- Print Report Manager (PRM) class which defines Report ID and the report parameters, handles report execution from building and opening the report dialog form to printing the report to a selected print destination.
- Report Menu Item which points to the report Print Report Manager (PRM) class. When opens the main()
method of the PRM class is invoked. This will result in opening the report dialog form and afterwards printing the report.
On the picture below is shown the PRM class which created by the wizard. In the class declaration we additionally prepared the macros and variables for the report parameter names and values that will be used by the class methods.
First, we will implement the addParameters() method in order to add all required report parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
public void addParameters() { DocReportParameter docReportParameter; // NOTE: In real case scenarios please use label IDs instead of literal strings. // PurchStatus. docReportParameter = DocReportParameter::constructFromEnumWithDefaultValue(enumStr(PurchStatus), PurchStatus::Invoiced); this.addParameter(docReportParameter); // OrderAccount. docReportParameter = DocReportParameter::constructFromEdt(extendedTypeStr(VendAccount), #OrderAccount); docReportParameter.parmLabelId("@SYS22016"); this.addParameter(docReportParameter); // InvoiceAccount. docReportParameter = DocReportParameter::constructFromEdt(extendedTypeStr(VendInvoiceAccount), #InvoiceAccount); this.addParameter(docReportParameter); // DeliveryDateFrom. docReportParameter = DocReportParameter::constructFromEdt(extendedTypeStr(DlvDate), #DeliveryDateFrom); docReportParameter.parmLabelId('From'); docReportParameter.parmHelpTextLabelId('Delivery date from'); this.addParameter(docReportParameter); // DeliveryDateTo. docReportParameter = DocReportParameter::constructFromEdt(extendedTypeStr(DlvDate), #DeliveryDateTo); docReportParameter.parmLabelId('To'); docReportParameter.parmHelpTextLabelId('Delivery date to'); this.addParameter(docReportParameter); // ShowLines. docReportParameter = DocReportParameter::constructFromEnum(enumStr(boolean), #ShowLines); docReportParameter.parmLabelId('Show lines'); docReportParameter.parmHelpTextLabelId('Should purchase order lines be shown'); this.addParameter(docReportParameter); // IncludeSalesTax. docReportParameter = DocReportParameter::constructFromEnumWithDefaultValue(enumStr(boolean), true, #IncludeSalesTax); docReportParameter.parmLabelId('Include sales tax'); this.addParameter(docReportParameter); } |
By opening the Report Menu Item (CTRL+O), the report dialog form is shown. The form looks like this:
Let’s implement buildParameterFormControls() method of the report PRM class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
protected void buildParameterFormControls(FormBuildGroupControl _parametersParentBuildGroupControl) { FormBuildGroupControl vendorFormBuildGroupControl; FormBuildGroupControl deliveryDateFormBuildGroupControl; // Put the OrderAccount and InvoiceAccount parameters into VendorGroup. vendorFormBuildGroupControl = _parametersParentBuildGroupControl.addControl(FormControlType::Group, 'VendorGroup'); vendorFormBuildGroupControl.caption("@SYS80105"); this.buildSingleParameterFormControl(#OrderAccount, vendorFormBuildGroupControl); this.buildSingleParameterFormControl(#InvoiceAccount, vendorFormBuildGroupControl); // Put the DeliveryDateFrom and DeliveryDateTo parameters into DeliveryDateGroup. deliveryDateFormBuildGroupControl = _parametersParentBuildGroupControl.addControl(FormControlType::Group, 'DeliveryDateGroup'); deliveryDateFormBuildGroupControl.columns(2); deliveryDateFormBuildGroupControl.caption("@SYS16056"); this.buildSingleParameterFormControl(#DeliveryDateFrom, deliveryDateFormBuildGroupControl); this.buildSingleParameterFormControl(#DeliveryDateTo, deliveryDateFormBuildGroupControl); // PurchStatus. this.buildSingleParameterFormControl(#PurchStatus, _parametersParentBuildGroupControl); // ShowLines. this.buildSingleParameterFormControl(#ShowLines, _parametersParentBuildGroupControl); // IncludeSalesTax. this.buildSingleParameterFormControl(#IncludeSalesTax, _parametersParentBuildGroupControl); // Change the right margin of the Parameter (parent) group. _parametersParentBuildGroupControl.rightMargin(10); } |
We have changed the default parameter ordering and introduce two groups on the report dialog form. The form now looks like as required:
Let’s implement the modifyParameterFormBuildControls() method of the report PRM class to enable custom lookup() and modified() methods of the form control bound to the OrderAccount report parameter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
protected void modifyParameterFormBuildControls(FormBuildGroupControl _parametersParentBuildGroupControl) { FormBuildStringControl fbscOrderAccount; super(_parametersParentBuildGroupControl); // Override lookup method of the form control bound to the OrderAccount parameter. fbscOrderAccount = this.getParameterFormBuildControl(#OrderAccount); fbscOrderAccount.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(DocPrintPurchOrderListPrintReport, OrderAccount_lookup), this); // Override modified method of the form control bound to the OrderAccount parameter. fbscOrderAccount = this.getParameterFormBuildControl(#OrderAccount); fbscOrderAccount.registerOverrideMethod(methodStr(FormStringControl, modified), methodStr(DocPrintPurchOrderListPrintReport, OrderAccount_modified), this); } public void OrderAccount_modified(FormStringControl _fscOrderAccount) { FormStringControl fscInvoiceAccount; _fscOrderAccount.modified(); // Write selected value to InvoiceAccount. fscInvoiceAccount = this.getParameterFormControl(#InvoiceAccount); fscInvoiceAccount.text(_fscOrderAccount.valueStr()); } public void OrderAccount_lookup(FormStringControl _fscOrderAccount) { SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(VendTable), _fscOrderAccount); Query query = new Query(); QueryBuildDataSource qbds; sysTableLookup.addLookupfield(fieldStr(VendTable, AccountNum), true); sysTableLookup.addLookupMethod(tableMethodStr(VendTable, name)); sysTableLookup.addLookupMethod(tableMethodStr(VendTable, countryRegionName)); sysTableLookup.setLabel('Country'); qbds = query.addDataSource(tablenum(VendTable)); qbds.addSortField(fieldStr(VendTable, AccountNum)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } |
See also
Download This Example >>
Docentric Basic Report Execution Hooks Overview >>
How to Run a Report in the Context of an Underlying Entity >>
How to Use More Than One Template for a Report >>