Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info
titleMinimum Requirements
  • Extension version MOB5.46
  • Business Central 16.0

...

  • 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

 

Step1Step 1: Create a new Enum Extension to support a new custom Report request page

...

This will allow us the link our custom RequestPage Handler to a specific Report Object in the Mobile Reports setup Page in BC.


enumextension51066"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 Report 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.


codeunit51083"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)]
    localprocedureOnLookupOnPrintReport_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)]
    localprocedureOnCreateReportParameters(_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: RecordItem;
    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;
}


Step3Step 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


...