ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Request for External] report 5405 "Calc. Consumption" - protected variables, public procedure & use GuiAllowed

Open matthiasrabus opened this issue 1 year ago • 3 comments

Why do you need this change?

We are converting one C/AL customer to the latest BC version. This customer has some changes to the standard report 5405 "Calc. Consumption" to allow it to run without UI and expose some functionality to other objects. To replicate the behavior, I would like to request the following changes

Describe the request

Please define these global variables as protected: Item ProdOrderLine ItemJnlLine NextConsumpJnlLineNo

    var
        LastItemJnlLine: Record "Item Journal Line";
        UOMMgt: Codeunit "Unit of Measure Management";
        Window: Dialog;
        PostingDate: Date;
        CalcBasedOn: Option "Actual Output","Expected Output";
        ToTemplateName: Code[10];
        ToBatchName: Code[10];

#pragma warning disable AA0074
        Text000: Label 'Calculating consumption...\\';
#pragma warning disable AA0470
        Text001: Label 'Prod. Order No.   #1##########\';
        Text002: Label 'Item No.          #2##########\';
        Text003: Label 'Quantity          #3##########';
#pragma warning restore AA0470
#pragma warning restore AA0074

    protected var
        LocationCode: Code[10];
        ReservedFromStock: Enum "Reservation From Stock";
        Item: Record Item;
        ProdOrderLine: Record "Prod. Order Line";
        ItemJnlLine: Record "Item Journal Line";
        NextConsumpJnlLineNo: Integer;

Please change the signature of the procedure CreateConsumpJnlLine to be public:

procedure CreateConsumpJnlLine(LocationCode: Code[10]; BinCode: Code[20]; OriginalQtyToPost: Decimal)

Please change the way how the dialog is shown, so that the report can be run without UI:

New global variable, plus setter and initialization:

var
    ShowDialog: Boolean; 

    procedure SetHideDialog(DoShowDialog: Boolean)
    begin
        ShowDialog := DoShowDialog;
    end;

    trigger OnInitReport()
    begin
        ShowDialog := true;
    end;

Change the following code segments:

Before:

    local procedure CreateConsumpJnlLine(LocationCode: Code[10]; BinCode: Code[20]; OriginalQtyToPost: Decimal)
    var
        Location: Record Location;
#if not CLEAN26
        ManufacturingSetup: Record Microsoft.Manufacturing.Setup."Manufacturing Setup";
#endif
        QtyToPost: Decimal;
        ShouldModifyItemJnlLine: Boolean;
        ShouldAdjustQty: Boolean;
    begin
        QtyToPost := OriginalQtyToPost;
        OnBeforeCreateConsumpJnlLine(LocationCode, BinCode, QtyToPost);

        Window.Update(3, QtyToPost);

#if not CLEAN26
.....

New:

    local procedure CreateConsumpJnlLine(LocationCode: Code[10]; BinCode: Code[20]; OriginalQtyToPost: Decimal)
    var
        Location: Record Location;
#if not CLEAN26
        ManufacturingSetup: Record Microsoft.Manufacturing.Setup."Manufacturing Setup";
#endif
        QtyToPost: Decimal;
        ShouldModifyItemJnlLine: Boolean;
        ShouldAdjustQty: Boolean;
    begin
        QtyToPost := OriginalQtyToPost;
        OnBeforeCreateConsumpJnlLine(LocationCode, BinCode, QtyToPost);

//CHANGED
     if  ShowDialog  then
        Window.Update(3, QtyToPost);
//CHANGED 

#if not CLEAN26
.....

Before:

            dataitem("Prod. Order Component"; "Prod. Order Component")
            {
                DataItemLink = Status = field(Status), "Prod. Order No." = field("No.");
                RequestFilterFields = "Item No.";

                trigger OnAfterGetRecord()
                var
                    NeededQty: Decimal;
                    IsHandled: Boolean;
                begin
                    Window.Update(2, "Item No.");

New:

            dataitem("Prod. Order Component"; "Prod. Order Component")
            {
                DataItemLink = Status = field(Status), "Prod. Order No." = field("No.");
                RequestFilterFields = "Item No.";

                trigger OnAfterGetRecord()
                var
                    NeededQty: Decimal;
                    IsHandled: Boolean;
                begin
                  //CHANGED
                 if  ShowDialog  then
                    Window.Update(2, "Item No.");
                  //CHANGED

Before:

            trigger OnAfterGetRecord()
            begin
                Window.Update(1, "No.");
            end;

            trigger OnPreDataItem()
            begin
                ItemJnlLine.SetRange("Journal Template Name", ToTemplateName);
                ItemJnlLine.SetRange("Journal Batch Name", ToBatchName);
                if ItemJnlLine.FindLast() then
                    NextConsumpJnlLineNo := ItemJnlLine."Line No." + 10000
                else
                    NextConsumpJnlLineNo := 10000;

                Window.Open(
                  Text000 +
                  Text001 +
                  Text002 +
                  Text003);
            end;

New:

            trigger OnAfterGetRecord()
            begin
               //CHANGED
               if  ShowDialog  then
               //CHANGED
                   Window.Update(1, "No.");
            end;

            trigger OnPreDataItem()
            begin
                ItemJnlLine.SetRange("Journal Template Name", ToTemplateName);
                ItemJnlLine.SetRange("Journal Batch Name", ToBatchName);
                if ItemJnlLine.FindLast() then
                    NextConsumpJnlLineNo := ItemJnlLine."Line No." + 10000
                else
                    NextConsumpJnlLineNo := 10000;
                    //CHANGED
                     if  ShowDialog  then
                    //CHANGED
                Window.Open(
                  Text000 +
                  Text001 +
                  Text002 +
                  Text003);
            end;

Internal work item: AB#599357

matthiasrabus avatar Sep 02 '25 14:09 matthiasrabus

Why do you need to hide the Window.Open / .Update? If it is executed in background, the commands are ignored, and if they run in foreground, the user has the option to cancel....

BardurKnudsen avatar Dec 01 '25 15:12 BardurKnudsen

@BardurKnudsen You are right, that is not required. Do you prefer if I remove the UI related requests and just keep the rest?

matthiasrabus avatar Dec 02 '25 10:12 matthiasrabus

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

Build ID: 44174.

JesperSchulz avatar Feb 20 '26 10:02 JesperSchulz