Skip to content

[Event Request] - Codeunit 7130 "Item Budget Management" #29970

@aulon97

Description

@aulon97

Why do you need this change?

We are working with table "Item Statistics Buffer" which contains the following standard CalcFields:

  • Field 50 "Budgeted Quantity" (Decimal)
  • Field 51 "Budgeted Sales Amount" (Decimal)
  • Field 52 "Budgeted Cost Amount" (Decimal)

Because these are standard CalcFields, their CalcFormula cannot be modified to meet our business requirements. To implement the required logic, we created three new custom decimal fields that replicate/extend these values. Those values are processed in 2 procedures in codeunit 7130.

Meaningful Justification:
Our reporting and analysis requirements depend on these “new budgeted” values, but we must apply additional calculation rules that are not supported by the existing CalcFormula. Without the ability to change the standard formulas, we cannot produce correct results using the standard fields.
To deliver accurate and consistent budget reporting while keeping the solution upgrade-safe, we introduced three custom decimal fields that represent the required budgeted values. We now need to calculate and maintain these custom fields in AL code.

Alternatives Evaluated:
We have reviewed all existing events in codeunit 7130 , in procedures CalculateAmount & SetAmount there is no event which we can use.

Justification for IsHandled:
We need is handled to avoid usage of standard calcfields and use custom ones.

Performance Considerations:
The custom budget fields are consumed only in a limited scope—specifically, one report and two matrix-style pages used to display aggregated values

Data Sensitivity Review:
The event parameters do not contain sensitive or confidential data. Exposing these is consistent with existing event signatures, and no additional data beyond what is already available in the production order line is required.

Multi-Extension Interaction:
Extensions that rely on this event must coordinate via dependency declarations. Partners can use EventSubscriberInstance = Manual to control execution order. The pattern is consistent with other core IsHandled events, so developers are familiar with the implications.

Describe the request

  1. New event in procedure CalculateAmount
 procedure CalculateAmount(ValueType: Enum "Item Analysis Value Type"; SetColumnFilter: Boolean; var ItemStatisticsBuf: Record "Item Statistics Buffer"; ItemBudgetName: Record "Item Budget Name"; ItemFilter: Text; SourceTypeFilter: Enum "Analysis Source Type"; SourceNoFilter: Text; DateFilter: Text; GlobalDim1Filter: Text; GlobalDim2Filter: Text; BudgetDim1Filter: Text; BudgetDim2Filter: Text; BudgetDim3Filter: Text; RowDimType: Enum "Item Budget Dimension Type"; RowDimCodeBuf: Record "Dimension Code Buffer"; ColDimType: Enum "Item Budget Dimension Type"; ColDimCodeBuf: Record "Dimension Code Buffer") Result: Decimal
    var
        IsHandled: Boolean; //New Code
    begin
        SetBufferFilters(
          ItemStatisticsBuf, ItemBudgetName, ItemFilter, SourceTypeFilter, SourceNoFilter,
          DateFilter, GlobalDim1Filter, GlobalDim2Filter, BudgetDim1Filter, BudgetDim2Filter, BudgetDim3Filter);
        SetDimensionFilters(ItemStatisticsBuf, RowDimType, RowDimCodeBuf);
        if SetColumnFilter then
            SetDimensionFilters(ItemStatisticsBuf, ColDimType, ColDimCodeBuf);

        OnCalculateAmountOnBeforeValueTypeCase(ValueType, ItemStatisticsBuf, Result, IsHandled); //New Event
        if IsHandled then //New Code
            exit(Result); //New Code

        case ValueType of
            ValueType::"Sales Amount":
                begin
                    ItemStatisticsBuf.CalcFields("Budgeted Sales Amount");
                    exit(ItemStatisticsBuf."Budgeted Sales Amount");
                end;
            ValueType::"Cost Amount":
                begin
                    ItemStatisticsBuf.CalcFields("Budgeted Cost Amount");
                    exit(ItemStatisticsBuf."Budgeted Cost Amount");
                end;
            ValueType::Quantity:
                begin
                    ItemStatisticsBuf.CalcFields("Budgeted Quantity");
                    exit(ItemStatisticsBuf."Budgeted Quantity");
                end;
            else begin
                OnCalculateAmountOnValueTypeCaseElse(ValueType, ItemStatisticsBuf, Result);
                exit(Result);
            end;
        end;
    end;

Event Signature:

  [IntegrationEvent(false, false)]
    local procedure OnCalculateAmountOnBeforeValueTypeCase(ValueType: Enum "Item Analysis Value Type"; ItemStatisticsBuf: Record "Item Statistics Buffer"; var Result: Decimal; var IsHandled: Boolean)
    begin
    end;
  1. New event in procedure SetAmount
  procedure SetAmount(ValueType: Enum "Item Analysis Value Type"; SetColumnFilter: Boolean; var ItemStatisticsBuf: Record "Item Statistics Buffer"; ItemBudgetName: Record "Item Budget Name"; ItemFilter: Text; SourceTypeFilter: Enum "Analysis Source Type"; SourceNoFilter: Text; DateFilter: Text; GlobalDim1Filter: Text; GlobalDim2Filter: Text; BudgetDim1Filter: Text; BudgetDim2Filter: Text; BudgetDim3Filter: Text; RowDimType: Enum "Item Budget Dimension Type"; RowDimCodeBuf: Record "Dimension Code Buffer"; ColDimType: Enum "Item Budget Dimension Type"; ColDimCodeBuf: Record "Dimension Code Buffer"; NewAmount: Decimal)
   var
       IsHandled: Boolean; //New Code
   begin
       SetBufferFilters(
         ItemStatisticsBuf, ItemBudgetName, ItemFilter, SourceTypeFilter, SourceNoFilter,
         DateFilter, GlobalDim1Filter, GlobalDim2Filter, BudgetDim1Filter, BudgetDim2Filter, BudgetDim3Filter);
       SetDimensionFilters(ItemStatisticsBuf, RowDimType, RowDimCodeBuf);
       if SetColumnFilter then
           SetDimensionFilters(ItemStatisticsBuf, ColDimType, ColDimCodeBuf);

       OnSetAmountOnBeforeValueTypeCase(ValueType, ItemStatisticsBuf, NewAmount, IsHandled); //New Event
       if IsHandled then//New Code
           exit; //New Code

       case ValueType of
           ValueType::"Sales Amount":
               begin
                   ItemStatisticsBuf.CalcFields("Budgeted Sales Amount");
                   ItemStatisticsBuf.Validate("Budgeted Sales Amount", NewAmount);
               end;
           ValueType::"Cost Amount":
               begin
                   ItemStatisticsBuf.CalcFields("Budgeted Cost Amount");
                   ItemStatisticsBuf.Validate("Budgeted Cost Amount", NewAmount);
               end;
           ValueType::Quantity:
               begin
                   ItemStatisticsBuf.CalcFields("Budgeted Quantity");
                   ItemStatisticsBuf.Validate("Budgeted Quantity", NewAmount);
               end;
           else
               OnSetAmountOnValueTypeCaseElse(ValueType, ItemStatisticsBuf);
       end;
   end;

Event Signature:

[IntegrationEvent(false, false)]
    local procedure OnSetAmountOnBeforeValueTypeCase(ValueType: Enum "Item Analysis Value Type"; var ItemStatisticsBuf: Record "Item Statistics Buffer"; var NewAmount: Decimal; var IsHandled: Boolean)
    begin
    end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an event

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions