Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Request] Table 37 "Sales Line" - OnBeforeCalcPosition #28173

Open
thomari opened this issue Feb 18, 2025 · 0 comments
Open

[Event Request] Table 37 "Sales Line" - OnBeforeCalcPosition #28173

thomari opened this issue Feb 18, 2025 · 0 comments

Comments

@thomari
Copy link

thomari commented Feb 18, 2025

Describe the request

Please add the following new publisher.

Previous Code

[Scope('OnPrem')]
procedure CalcPosition(FixedNumber: Integer)
var
    PosBefore: Integer;
    PosAfter: Integer;
begin
     if not (CheckQuoteMgtPermission() or (CopyStr(SerialNumber, 7, 3) = '000')) then
         exit;

    if (FixedNumber >= 10) and ("No." <> '') then begin
        Position := FixedNumber;
        exit;
    end;
    if HasTypeToFillMandatoryFields() and ("No." <> '') then begin
        PosBefore := 0;
        PosAfter := 0;
        SalesLine2.Reset();
        SalesLine2 := Rec;
        SalesLine2.SetRange("Document No.", "Document No.");
        SalesLine2.SetRange("Document Type", "Document Type");

        SalesLine2.SetRange(Type, Type::"G/L Account", Type::"Charge (Item)");
        SalesLine2.SetFilter("No.", '<>%1', '');
        if SalesLine2.Find('<') then
            PosBefore := SalesLine2.Position;
        SalesLine2 := Rec;
        if SalesLine2.Find('>') then
            PosAfter := SalesLine2.Position;

        if PosAfter > 0 then begin
            if PosAfter - PosBefore < 2 then
                Error(Text90801 + Text90802, "Document Type");
            Position := Round((PosAfter + PosBefore) / 2, 1);
        end else
            Position := PosBefore + 10;
    end else
        Position := 0;
end;

New Code

[Scope('OnPrem')]
procedure CalcPosition(FixedNumber: Integer)
var
    PosBefore: Integer;
    PosAfter: Integer;
    IsHandled: Boolean;
begin
    OnBeforeCalcPosition(Rec, IsHandled);
    if IsHandled then begin
        exit;
    end;

     if not (CheckQuoteMgtPermission() or (CopyStr(SerialNumber, 7, 3) = '000')) then
         exit;

    if (FixedNumber >= 10) and ("No." <> '') then begin
        Position := FixedNumber;
        exit;
    end;
    if HasTypeToFillMandatoryFields() and ("No." <> '') then begin
        PosBefore := 0;
        PosAfter := 0;
        SalesLine2.Reset();
        SalesLine2 := Rec;
        SalesLine2.SetRange("Document No.", "Document No.");
        SalesLine2.SetRange("Document Type", "Document Type");

        SalesLine2.SetRange(Type, Type::"G/L Account", Type::"Charge (Item)");
        SalesLine2.SetFilter("No.", '<>%1', '');
        if SalesLine2.Find('<') then
            PosBefore := SalesLine2.Position;
        SalesLine2 := Rec;
        if SalesLine2.Find('>') then
            PosAfter := SalesLine2.Position;

        if PosAfter > 0 then begin
            if PosAfter - PosBefore < 2 then
                Error(Text90801 + Text90802, "Document Type");
            Position := Round((PosAfter + PosBefore) / 2, 1);
        end else
            Position := PosBefore + 10;
    end else
        Position := 0;
end;

Event

[IntegrationEvent(false, false)]
local procedure OnBeforeCalcPosition(var Rec: Record "Sales Line"; var IsHandled: Boolean)
begin
end;

Additional context

We use our own CalcPosition procedure for different BC localisations and need to disable the base CalcPosition procedure for CH localisations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant