web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Add Custom OnDelete Trigger on Base Function

(0) ShareShare
ReportReport
Posted on by 45

Hi all,

I need to skip the below highlighted function based on few condition. It is available in sales line OnDelete trigger. I did not find any integration event to skip this.

Is there any way to create a new OnDelete trigger and skip the base function.

trigger OnDelete()
    var
        SalesCommentLine: Record "Sales Comment Line";
        CapableToPromise: Codeunit "Capable to Promise";
        JobCreateInvoice: Codeunit "Job Create-Invoice";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        OnDeleteOnBeforeTestStatusOpen(Rec, IsHandled);
        if not IsHandled then
            TestStatusOpen();

        if (Quantity <> 0) and ItemExists("No."then begin
            ReserveSalesLine.DeleteLine(Rec);
            CheckReservedQtyBase();
            if "Shipment No." = '' then
                TestField("Qty. Shipped Not Invoiced", 0);
            if "Return Receipt No." = '' then
                TestField("Return Qty. Rcd. Not Invd.", 0);
            WhseValidateSourceLine.SalesLineDelete(Rec);
        end;

        if ("Document Type" = "Document Type"::Order) and (Quantity <> "Quantity Invoiced"then
            TestField("Prepmt. Amt. Inv.", "Prepmt Amt Deducted");

        CleanDropShipmentFields();
        CleanSpecialOrderFieldsAndCheckAssocPurchOrder();
        CatalogItemMgt.DelNonStockSales(Rec);

        if "Document Type" = "Document Type"::"Blanket Order" then begin
            SalesLine2.Reset();
            SalesLine2.SetCurrentKey("Document Type", "Blanket Order No.", "Blanket Order Line No.");
            SalesLine2.SetRange("Blanket Order No.", "Document No.");
            SalesLine2.SetRange("Blanket Order Line No.", "Line No.");
            if SalesLine2.FindFirst then
                SalesLine2.TestField("Blanket Order Line No.", 0);
        end;

        if Type = Type::Item then begin
            ATOLink.DeleteAsmFromSalesLine(Rec);
            DeleteItemChargeAssignment("Document Type", "Document No.", "Line No.");
        end;

        if Type = Type::"Charge (Item)" then
            DeleteChargeChargeAssgnt("Document Type", "Document No.", "Line No.");

        if ("Document Type" = "Document Type"::Order) then
            CapableToPromise.RemoveReqLines("Document No.", "Line No.", 0, false);

        if "Line No." <> 0 then begin
            SalesLine2.Reset();
            SalesLine2.SetRange("Document Type", "Document Type");
            SalesLine2.SetRange("Document No.", "Document No.");
            SalesLine2.SetRange("Attached to Line No.", "Line No.");
            SalesLine2.SetFilter("Line No.", '<>%1', "Line No.");
            OnDeleteOnAfterSetSalesLineFilters(SalesLine2);
            SalesLine2.DeleteAll(true);
        end;

        if "Job Contract Entry No." <> 0 then
            JobCreateInvoice.DeleteSalesLine(Rec);

        SalesCommentLine.SetRange("Document Type", "Document Type");
        SalesCommentLine.SetRange("No.", "Document No.");
        SalesCommentLine.SetRange("Document Line No.", "Line No.");
        if not SalesCommentLine.IsEmpty then
            SalesCommentLine.DeleteAll();

        // In case we have roundings on VAT or Sales Tax, we should update some other line
        if (Type <> Type::" ") and ("Line No." <> 0) and ("Attached to Line No." = 0) and ("Job Contract Entry No." = 0) and
           (Quantity <> 0) and (Amount <> 0) and (Amount <> "Amount Including VAT") and not StatusCheckSuspended
        then begin
            Quantity := 0;
            "Quantity (Base)" := 0;
            "Qty. to Invoice" := 0;
            "Qty. to Invoice (Base)" := 0;
            "Line Discount Amount" := 0;
            "Inv. Discount Amount" := 0;
            "Inv. Disc. Amount to Invoice" := 0;
            UpdateAmounts();
        end;

        if "Deferral Code" <> '' then
            DeferralUtilities.DeferralCodeOnDelete(
                "Deferral Document Type"::Sales.AsInteger()'''',
                "Document Type".AsInteger(), "Document No.", "Line No.");
    end;
I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    Create a custom page action and choose delete but don’t validate, delete(false). This will skip the OnDelete code. So all the other good stuff it does would need catering for in the routine.

    I believe you can request integration events via GitHub too.

  • Lars Lohndorf-Larsen Profile Picture
    on at
  • Verified answer
    Revanth M Profile Picture
    45 on at

    Thank you for your reply!

    I will raise a request in github for integration event.

    This code was executed at the time of recreating a sales line. I found one integeration event there, I will try to skip salesline.deleteall(true) but I hope I need to handle this in CreateSalesLine Function too.

    Thank you!

    Regards

    Revanth

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,010

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,270 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,085 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans