Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.
This repository was archived by the owner on Oct 19, 2026. It is now read-only.

[Event Request] Codeunit 5900 "ServOrderManagement".InsertServCost #30421

Closed

Description

@fridrichovsky

Why do you need this change?

Problem statement:
The logic change introduces an extension point for travel fee determination. The new publisher allows extensions to override the standard Service Zone Code-based lookup logic by handling the process before the Service Zone Code validation and cost search. If handled, a custom logic can be implemented to determine the appropriate travel cost record. After finding the relevant cost record, a new service document line with type Cost is created and the required values are populated automatically.

Alternatives evaluated:
No other alternative solution exists for this change.

Proposed publisher location:
Object: Codeunit 5900 "ServOrderManagement"
Procedure: InsertServCost

Placement rationale:
The publisher is placed before the Service Zone Code validation and travel cost lookup logic. This allows extensions to override the standard travel fee determination logic by setting the IsHandled parameter and providing their own implementation.

Performance & data considerations:
The event is triggered only when a travel fee is being created in the InsertServCost procedure. The frequency depends on service document processing and is expected to be low. The event does not introduce additional database operations by itself. Subscribers should implement efficient logic when searching for alternative Service Cost records. No sensitive data is exposed; only Service Header, Service Cost and IsHandled parameters are provided.

MultiΓÇæextension interaction:
Multiple extensions may subscribe to this event. Since the event uses the IsHandled pattern, only one subscriber should take responsibility for overriding the standard behavior. Extensions should avoid conflicting implementations and ensure that IsHandled is set only when they fully handle the travel fee determination logic.

Justification for using IsHandled over alternatives:
The IsHandled pattern is used because the purpose of this publisher is to allow extensions to replace the standard travel fee determination logic. Alternative approaches, such as adding events after the standard lookup or after the record insertion, would not allow extensions to prevent the execution of the existing Service Zone Code validation and cost lookup logic.

Describe the request

Proposed code snippet (before -> after):

procedure InsertServCost(ServInvLine: Record "Service Line"; CostType: Integer; LinktoServItemLine: Boolean): Boolean
    var
        ServCost: Record "Service Cost";
        ServHeader: Record "Service Header";
        ServInvLine2: Record "Service Line";
        ServMgtSetup: Record "Service Mgt. Setup";
        //----------------------------OnInsertServCostOnCostTypeOneOnAfterServCostGet::BEGIN
        IsHandled: Boolean;
        //----------------------------OnInsertServCostOnCostTypeOneOnAfterServCostGet::END
        NextLine: Integer;
    begin
        ServHeader.Get(ServInvLine."Document Type", ServInvLine."Document No.");

        ServInvLine2.Reset();
        ServInvLine2.SetRange("Document Type", ServInvLine."Document Type");
        ServInvLine2.SetRange("Document No.", ServInvLine."Document No.");
        ServInvLine2 := ServInvLine;

        NextLine := ServInvLine.GetNextLineNo(ServInvLine, false);
        if NextLine = 0 then
            Error(Text008, ServInvLine.TableCaption());

        case CostType of
            0: // Travel Fee
                begin
                    //-----------------------------------------------------------OnInsertServCostOnCostTypeZeroOnBeforeTestServiceZoneCode::BEGIN
                    OnInsertServCostOnCostTypeZeroOnBeforeTestServiceZoneCode(ServHeader, ServCost, IsHandled);
                    if not IsHandled then begin
                        ServHeader.TestField("Service Zone Code");
                        ServCost.Reset();
                        ServCost.SetCurrentKey("Service Zone Code");
                        ServCost.SetRange("Service Zone Code", ServHeader."Service Zone Code");
                        ServCost.SetRange("Cost Type", ServCost."Cost Type"::Travel);
                        if not ServCost.FindFirst() then
                            Error(
                              Text009,
                              ServCost.TableCaption(), ServCost.FieldCaption("Service Zone Code"), ServHeader."Service Zone Code");
                    end;
                    //-----------------------------------------------------------OnInsertServCostOnCostTypeZeroOnBeforeTestServiceZoneCode::END
                    ServInvLine2.Init();
                    if LinktoServItemLine then begin
                        ServInvLine2."Service Item Line No." := ServInvLine."Service Item Line No.";
                        ServInvLine2."Service Item No." := ServInvLine."Service Item No.";
                        ServInvLine2."Service Item Serial No." := ServInvLine."Service Item Serial No.";
                    end;
                    ServInvLine2."Document Type" := ServHeader."Document Type";
                    ServInvLine2."Document No." := ServHeader."No.";
                    ServInvLine2."Line No." := NextLine;
                    ServInvLine2.Type := ServInvLine2.Type::Cost;
                    ServInvLine2.Validate("No.", ServCost.Code);
                    ServInvLine2.Validate("Unit of Measure Code", ServCost."Unit of Measure Code");
                    ServInvLine2.Insert(true);
                    exit(true);
                end;
            1: // Starting Fee
                begin
                    ServMgtSetup.Get();
                    ServMgtSetup.TestField("Service Order Starting Fee");
                    ServCost.Get(ServMgtSetup."Service Order Starting Fee");
                    OnInsertServCostOnCostTypeOneOnAfterServCostGet(ServHeader, ServCost);
                    ServInvLine2.Init();
                    if LinktoServItemLine then begin
                        ServInvLine2."Service Item Line No." := ServInvLine."Service Item Line No.";
                        ServInvLine2."Service Item No." := ServInvLine."Service Item No.";
                        ServInvLine2."Service Item Serial No." := ServInvLine."Service Item Serial No.";
                    end;
                    ServInvLine2."Document Type" := ServHeader."Document Type";
                    ServInvLine2."Document No." := ServHeader."No.";
                    ServInvLine2."Line No." := NextLine;
                    ServInvLine2.Type := ServInvLine2.Type::Cost;
                    ServInvLine2.Validate("No.", ServCost.Code);
                    ServInvLine2.Validate("Unit of Measure Code", ServCost."Unit of Measure Code");
                    ServInvLine2.Insert(true);
                    exit(true);
                end;
            else
                exit(false);
        end;
    end;

    //----------------------------OnInsertServCostOnCostTypeOneOnAfterServCostGet::BEGIN
    [IntegrationEvent(false, false)]
    local procedure OnInsertServCostOnCostTypeZeroOnBeforeTestServiceZoneCode(ServHeader: Record "Service Header"; var ServCost: Record "Service Cost"; var IsHandled: Boolean)
    begin
    end;
    //----------------------------OnInsertServCostOnCostTypeOneOnAfterServCostGet::END

Internal work item: AB#647292

Activity

  1. added
    missing-infoThe issue misses information that prevents it from completion.
    on Aug 14, 2026
  2. github-actions commented on Aug 14, 2026

    @github-actions
    Contributor

    Hi F!do (@fridrichovsky),

    Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.

    📚 Extensibility Guidelines

    Missing Information:

    • Bypass of standard validation and error handling: Please confirm that your scenario requires skipping ServHeader.TestField("Service Zone Code") and the standard Service Cost lookup/error flow when IsHandled is set, and describe what validation and error handling your subscriber will enforce instead.
    • Requested extensibility shape: Please clarify whether you specifically need an IsHandled event that replaces the current travel fee resolution block, or whether extracting that logic into a dedicated helper procedure would satisfy your scenario.

    Please update the issue with the missing details. We'll automatically re-analyze once updated.

    Note

    Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

    Tip

    Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

  3. fridrichovsky commented on Aug 14, 2026

    @fridrichovsky
    ContributorAuthor

    /not-accurate We need skip TestField and Setrange and we change message that explain filter different way then standard. We don't use Service Zone Codes so we have to change whole block. If you create new function for check and this function will have IsHande as first line it can be used.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::ServOrderManagement, OnInsertServCostOnCostTypeZeroOnBeforeTestServiceZoneCode, '', false, false)]
    local procedure OnInsertServCostOnCostTypeZeroOnBeforeTestServiceZoneCode(ServHeader: Record "Service Header"; var ServCost: Record "Service Cost"; var IsHandled: Boolean)
    var
        Text009Err: Label 'Travel fee in the %1 table with %2 %3 cannot be found.', Comment = '%1 - Table name, %2 - Field name, %3 - Field value';
    begin
        ServCost.Reset();
        ServCost.SetRange("Cost Type", ServCost."Cost Type"::Travel);
        if not ServCost.FindFirst() then
            Error(
              Text009Err,
              ServCost.TableCaption(), ServCost.FieldCaption("Cost Type"), ServCost."Cost Type"::Travel);
        IsHandled := true;
    end;
  4. github-actions commented on Aug 14, 2026

    @github-actions
    Contributor

    ✅ Feedback recorded
    Thanks — your /not-accurate feedback has been logged and will be reviewed.

  5. added
    event-requestRequest for adding an event
    SCMGitHub request for SCM area
    ext-ready-to-implementReviewed and ready to implement and create PR
    and removed
    missing-infoThe issue misses information that prevents it from completion.
    on Aug 19, 2026
  6. JesperSchulz commented on Sep 10, 2026

    @JesperSchulz
    Contributor

    The requested change has been implemented in microsoft/BCApps#10424 and is present in subsequent integration builds. The corresponding Azure Boards item 647292 was not moved out of New, so the automatic GitHub closure did not run. Closing this issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an eventext-ready-to-implementReviewed and ready to implement and create PR

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions