| Docs Help
  AppSource  
Docs  /  Excel Report Builder  /  Information for Developers

 Runnable Codeunits


2023/12/01 • 4 min. to read
On the Excel Evaluation Card page, a Codeunit for the evaluation can be specified in the Codeunit to Run field. This can be used, for example, to display notes or to recalculate or update data directly before the evaluation is executed. Edit Evaluations, General, Edit Excel Evaluation In order to ensure that only Codeunits can be executed that were also created for the Excel Report Builder, they must be additionally included or unlocked via an EventSubscriber. The Excel Report Builder calls the Codeunit for an evaluation via the OnRun() trigger of the Codeunit. Additional information for the user and the Call Location of the Codeunit is specified via the EventSubscriber. Possible Call Locations
  • OnShowExecutePage When the execute page is displayed. This position is particularly suitable for displaying users general information about the evaluation. Example:
  • OnShowFilterPage When the filter page is displayed. Similar to OnShowExecutePage only directly after the execute page. The call is made even if no filter page is displayed.
  • OnBeforeExecute Before the evaluation is executed. This position is particularly suitable for displaying a confirmation and/or for recalculating/updating data.

Example 1

As a simple example, you can specify the Codeunit 70171837 "NCE Show Schedule Message" in an evaluation. This Codeunit is delivered with the Excel Report Builder and causes the following additional message to be displayed when the evaluation is executed:

Implementation

The Codeunit is structured as follows and can be used as a template for your own requirements:
codeunit 70171837 "NCE Show Schedule Message"
{
    trigger OnRun()
    begin
        if (CurrentClientType = ClientType::Background) then
            exit;
        Message(ScheduleMsg);
    end;

    var
        ScheduleMsg: Label 'This evaluation should be scheduled.\As soon as the Excel workbook has been created, a message appears in the Report Inbox.', Comment = 'DEU="Diese Auswertung sollte als Plan ausgeführt werden.\Sobald die Excel-Arbeitsmappe erstellt wurde, erscheint eine Meldung im Berichtseingang."';

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"NCE Runnable Codeunit Mgt.", 'OnAddAllowedCodeunitsToRun', '', false, false)]
    local procedure NCERunnableCodeunitMgt_OnAddAllowedCodeunitsToRun(var TempNCERunnableCodeunit: Record "NCE Runnable Codeunit" temporary)
    var
        HelpTxt: Label 'This Codeunit causes the following additional message to be displayed when the evaluation is executed:\\', Comment = 'DEU="Diese Codeunit bewirkt, dass beim Ausführen der Auswertung zusätzliche folgende Meldung angezeigt wird:\\"';
    begin
        TempNCERunnableCodeunit.Add(Codeunit::"NCE Show Schedule Message", HelpTxt + '"' + ScheduleMsg + '"', "NCE Codeunit Call Location"::OnShowExecutePage);
    end;
}
Via TempNCERunnableCodeunit.Add the Codeunit will be included or unlocked in the Excel Report Builder. Parameter
  • CodeunitID

    Important

    The first parameter CodeunitID determines which Codeunit it is.
    TempNCERunnableCodeunit.Add(Codeunit::"NCE Show Schedule Message", ...
    The value must match the name of the Codeunit.
  • CodeunitHelpText This text is displayed when selecting the Codeunit to Run in the Excel Evaluation Card. Information about the purpose and usage of the Codeunit should be provided here.
  • CodeunitCallLocation Determines where the Codeunit is called.

Example 2

Another simple example is the Codeunit 70171836 "NCE Confirm Long Run Time". This Codeunit is also delivered with the Excel Report Builder and causes the following additional confirmation to be displayed when the evaluation is executed:

Implementation

The Codeunit is structured as follows and can be used as a template for your own requirements:
codeunit 70171836 "NCE Confirm Long Run Time"
{
    trigger OnRun()
    var
        ConfirmManagement: Codeunit "Confirm Management";
    begin
        if (CurrentClientType = ClientType::Background) then
            exit;
        if not ConfirmManagement.GetResponseOrDefault(LongRuntimeMsg, true) then
            Error('');
    end;

    var
        LongRuntimeMsg: Label 'It will take a longer time to execute this evaluation.\Do you want to execute the evaluation anyway?', Comment = 'DEU="Das Ausführen dieser Auswertung wird länger dauern.\Möchten Sie die Auswertung trotzdem ausführen?"';

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"NCE Runnable Codeunit Mgt.", 'OnAddAllowedCodeunitsToRun', '', false, false)]
    local procedure NCERunnableCodeunitMgt_OnAddAllowedCodeunitsToRun(var TempNCERunnableCodeunit: Record "NCE Runnable Codeunit" temporary)
    var
        HelpTxt: Label 'This Codeunit causes the following additional confirmation to be displayed when the evaluation is executed:\\', Comment = 'DEU="Diese Codeunit bewirkt, dass beim Ausführen der Auswertung zusätzliche folgende Bestätigung angezeigt wird:\\"';
    begin
        TempNCERunnableCodeunit.Add(Codeunit::"NCE Confirm Long Run Time", HelpTxt + '"' + LongRuntimeMsg + '"', "NCE Codeunit Call Location"::OnBeforeExecute);
    end;
}

See also




Submit feedback for
DE|EN Imprint
<>