Description
Create a custom RequestPage Handler for a Report object for use with Report Print.
A RequestPage Handler is required to print a standard or custom Report Object from the mobile device.
Use case
In this example, we want to print the standard Item GTIN Label report from the mobile device.
It will require us to extend the RequestPage Handler Enum and to create a new RequestPage Handler.
Get started
This customization can be divided into 3 steps.
- Step 1: Create a new Enum Extension to support a new custom Report request page
- Step 2: Create a new Codeunit to be used as a new custom RequestPage Handler
- Step 3: Add the report and the RequestPage Handler to the Mobile Reports set up in Business Central
Step 1: Create a new Enum Extension to support a new custom Report request page
First, we need to extend the MOB RequestPage Handler Enum Object.
This will allow us the link our custom RequestPage Handler to a specific Report Object in the Mobile Reports setup Page in BC.
enumextension 51066 "RequestPage Ext" extends "MOB RequestPage Handler"
{
//
// [How to] [How-to: Create custom RequestPage Handler]
//
value(50100; "Item GTIN Label")
{
Caption = 'Item GTIN Label', Locked = true;
}
}
Step 2: Create a new Codeunit to be used as a new custom RequestPage Handler
Create a new codeunit and implement the two required events to define the steps shown on the mobile device and the values transferred to the Report request page.
Using event OnLookupOnPrintReport_OnAddStepsForReport
In this event, we must define the values we want to collect from the mobile device when printing the report.
This is done by adding steps to specify the values we want to collect. In the example below, we ask for the Item Number and Printer Name.
Using event OnCreateReportParameters
In this event, we read the collected value from the Request Values and link the values to specific fields on the Report request page.
The values on the Report request page can be divided into two groups.
_OptionsFieldValues
Reference to the fields on the Report request page.
Typically used for optional request page fields
_DataItemViews
Reference to the Report Data Items.
Typically used to apply record filters.
codeunit 51083 "ItemGTIN Label ReqPage Handler"
{
//
// [How to] [How-to: Create custom RequestPage Handler]
//
/// <summary>
/// Custom Report Handler for standard Report ID 6625 "Item GTIN Label"
/// Please note that this report is only available from BC23
/// </summary>
// ----- STEPS -----
/// <summary>
/// Create the required steps for your Report Object.
/// This will be the steps that must be collected from the mobile user, when printing this report.
/// </summary>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB Report Print Lookup", 'OnLookupOnPrintReport_OnAddStepsForReport', '', true, true)]
local procedure OnLookupOnPrintReport_OnAddStepsForReport(_MobReport: Record "MOB Report"; var _RequestValues: Record "MOB NS Request Element"; _SourceRecRef: RecordRef; var _Steps: Record "MOB Steps Element"; var _IsHandled: Boolean)
var
MobReportPrintSteps: Codeunit "MOB Report Print Lookup";
ItemNo: Text;
begin
if _MobReport."RequestPage Handler" <> _MobReport."RequestPage Handler"::"Item GTIN Label" then
exit;
// Read values from Request
ItemNo := _RequestValues.GetValueOrContextValue('ItemNumber');
// Create steps
_Steps.Create_TextStep_ItemNumber(10);
_Steps.Set_defaultValue(ItemNo);
// Printer related steps
MobReportPrintSteps.CreateReportPrinterAndNoOfCopiesSteps(_MobReport, _RequestValues, _Steps, 90, 0);
// The report type is handled but might not always return any steps and should therefore maybe not be shown
_IsHandled := true;
end;
// ----- REQUEST PAGE PARAMETERS -----
/// <summary>
/// This Event is responsible for translating Mobile RequestValues into input that the Report can understand with its RequestPage.
/// </summary>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB ReportParameters Mgt.", 'OnCreateReportParameters', '', true, true)]
local procedure OnCreateReportParameters(_MobReport: Record "Mob Report"; _SourceRecRef: RecordRef; var _RequestValues: Record "MOB NS Request Element" temporary; var _OptionsFieldValues: Record "MOB ReportParameters Element"; var _DataItemViews: Record "MOB ReportParameters Element"; var _IsHandled: Boolean)
var
Item: Record Item;
begin
if _MobReport."RequestPage Handler" <> _MobReport."RequestPage Handler"::"Item GTIN Label" then
exit;
// Everything in the Parameter shall be formatted in XML format to support non-text fields in the request page
// Example on how to transfer value from _RequestValue collect from Mobile Device in field 'MyField' to the request page named 'MyFieldReq'
// _OptionsFieldValues.SetValue('MyFieldReq', _RequestValues.GetValue('MyField'));
// Request page dataItem: Items
// Generate an Item variable with filters to be set in the Item dataitem of the report
// I.e. like this: <DataItem name="Items">VERSION(1) SORTING(Field1) WHERE(Field1=1(70000))</DataItem>
Item.SetRange("No.", _RequestValues.Get_ItemNumber());
_DataItemViews.SetValue('Items', Item.GetView(false));
_IsHandled := true; // Multiple subscribers can add to the parameters for the same report handler - this just indicates at least one subscriber has handled this report type
end;
}
Step 3: Add the report and RequestPage Handler to the Mobile Reports set up in Business Central
When the customizations described in steps 1 + 2 are done, you can set up and use your custom RequestPage Handler.
Please refer to this guide on how to set up a new Report and new RequestPage Handler Set up Report Print