Hi, Readers.
Today I would like to briefly talk about if it is possible to change default options/filters in the request page of report.
A request page is a page that is run before the report or XMLport starts to execute. Request pages enable end users to specify options and filters for a report and an XMLport.
Request pages are defined as part of designing a Report object, a Report Extension Object, or an XMLport object.
For exmaple, in report 1305 “Standard Sales – Order Conf.”:
So can we change default options/filters? (In this post, we only talk about the request page of the report).
As you might know, options in the request page are generally global variables. In Can we access global variables from page extensions or table extensions? Yes, But……, we have discussed that if the variables of the standard object are set as protected variables, we can access them from our extensions.
For example,
This is also available for reports as well.
For example, in report 1305 “Standard Sales – Order Conf.”:
protected var
We can do the following in Report Extension.
Looks good.
Source code:
reportextension 50112 ZYStandardSalesOrderConfExt extends "Standard Sales - Order Conf."
{
requestpage
{
trigger OnOpenPage()
begin
LogInteraction := false;
ArchiveDocument := false;
DisplayAssemblyInformation := false;
end;
}
}
This is the easiest way. So first check whether the options/filters you need to change are defined as protected var. But unfortunately, this property is not set in all standard reports. So we can’t change default options/filters in this way for all standard reports. But there are a couple of workarounds we can do.
First let’s look at the standard functions.
1. Using Report Settings page
We discussed this function in How to manage saved settings for Reports (Used options and filters). Let’s review it briefly.
If you set SaveValues = True in Request Page of Report Object.
After the report is printed, Use default values from field will be shown. (Clicking Preview seems to have no effect, you need to click Print)
Business Central automatically saves the last used options and filters. Actually, a report can include one or more saved settings that users can apply to the report from the request page.
Select – Report Settings page will be opened.
Or, enter Report Settings in tell me, and then choose the related link.
Let’s look at another example. Choose the New action
Set the name, Report ID, Company Name and whether it is Shared with All Users. Then choose OK.
Shared with All Users
Specifies whether the report settings are available to all users or only the user assigned to the settings.
The Request Page of the report will automatically open at this time, and you can set the options and filters you want to save, then choose OK.
For example,
Of course, you can choose Edit to edit the options/filters just set on the Request page, or choose Copy to copy it and recreate a new Report Setting.
Then we can use it in the report.
Test video:
Saved settings are basically predefined options and filters. Using saved settings is a fast and reliable way to consistently generate reports that contain the correct data. But please note that this feature is not available for all reports.
Note:
The Saved Settings feature is available only on reports where the SaveValues property of the report’s request page is set to Yes. The SaveValues property is set in the development environment.
For example, this property is not set in report 1 “Chart of Accounts”.
We can add new settings for this report in the Report Settings page.
But when opening it, the Use default values from field cannot be found.
Next, let’s take a look. Is there any solution if it is customized?
2. Using Report.Run(Integer [, Boolean] [, Boolean] [, var Record]) Method or Report.RunModal(Integer [, Boolean] [, Boolean] [, var Record]) Method
Both methods load and execute the report that you specify. Each has a parameter, [Optional] Record: Specifies which record to use in the report. Any filters that are attached to the record that you specify are used.
We can simply do the following example to print the GL accounts selected by the user.
PS: This filter will not be displayed on the Request Page.
Test video:
There are two main limitations to this approach. First, we cannot change the variable values on the request page. Second, we can only add filtering for top-level data items.
Source code:
pageextension 50117 ZYChartOfAccountsExt extends "Chart of Accounts"
{
actions
{
addfirst(processing)
{
action(PrintSelectedChartofAccounts)
{
Caption = 'Print Selected Chart of Accounts';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
Image = Print;
trigger OnAction()
var
GLAccount: Record "G/L Account";
begin
GLAccount.Reset();
CurrPage.SetSelectionFilter(GLAccount);
Report.Run(Report::"Chart of Accounts", true, false, GLAccount);
end;
}
}
}
}
3. Using Report.RunRequestPage(Integer [, Text]) Method
This method is similar to the first method, you can first save the request page parameters in the XML string, and then use it when running the report.
Report.RunRequestPage(Integer [, Text]) Method: Runs the request page for a report without running the report. Returns an XML string that contains the request page parameters that are entered on the request page.
This method opens the request page for the specified report to allow the user to provide parameters for the report. When the user closes the request page by choosing the OK button, a string that contains the parameter values that were set by the user is returned. When the user chooses the Cancel button, an empty string will be returned.
To make it simple to understand, I made a simple tool.
Test video:
And, the returned parameter string can be picked up by calling one of the following methods:
For exmaple,
PS:
1. Because the request page runs in the context of where it was invoked from, users cannot bookmark a link to this page from the user interface.
2. You can use these methods to schedule reports in the job queue.
Source Code: Github
page 50103 "ZY Get Request Page Parameters"
{
PageType = Card;
Caption = 'Get Request Page Parameters';
UsageCategory = Tasks;
ApplicationArea = All;
layout
{
area(content)
{
field(ReportId; ReportId)
{
ApplicationArea = All;
Caption = 'Report Id';
TableRelation = AllObjWithCaption."Object ID" where("Object Type" = const(Report));
trigger OnValidate()
var
AllObjWithCaption: Record AllObjWithCaption;
begin
if AllObjWithCaption.Get(AllObjWithCaption."Object Type"::Report, ReportId) then begin
ReportName := AllObjWithCaption."Object Name";
XMLString := '';
end;
end;
}
field(ReportName; ReportName)
{
ApplicationArea = All;
Caption = 'Report Name';
Editable = false;
}
field(XMLString; XMLString)
{
ApplicationArea = All;
Caption = 'XML String';
Editable = false;
MultiLine = true;
}
}
}
actions
{
area(Processing)
{
action(GetReportReuqestPageParameters)
{
Caption = 'Get Report Reuqest Page Parameters';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
trigger OnAction()
var
ComfirmReport: Report "Standard Sales - Order Conf.";
begin
XMLString := Report.RunRequestPage(ReportId);
end;
}
action(RunReport)
{
Caption = 'Run Report';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
trigger OnAction()
begin
Report.Print(ReportId, XMLString);
end;
}
}
}
var
ReportId: Integer;
ReportName: Text;
XMLString: Text;
}
END
Hope this will help.
Thanks for your reading.
ZHU
コメント