Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

error while deleting sales order

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Dear Experts,

I need to delete blank sales orders. Please advise. 

*This post is locked for comments

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,159 Super User 2025 Season 1 on at
    RE: error while deleting sales order

    try suresh's suggestion.

    clear the posting no.  and other no. series fields from table 36 for respective order and try deleting.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: error while deleting sales order

    Hi,

    I have tried as suggested by Saurabh Shah and Alexander Sir,  Actuall these sales order are blank nothing is mentioned there except sales order no. and I have searched sale order no. in posted sales invoice list this order no has no invoice but the PSI no which is coming in error is there in the posted sales invoice list with different sales order no. 
    Kindly advise

    sales-order-list.png

     

    sales-order-list.png

     

    Thanks

    With Regards

    Mandeep Kaur

  • AbduTeeyech Profile Picture
    AbduTeeyech 424 on at
    RE: error while deleting sales order

    Did you try Alexander 's suggestion? to use delete invoiced sales orders option in nav?

  • Suggested answer
    Saurabh Shah Profile Picture
    Saurabh Shah 4,560 on at
    RE: error while deleting sales order

    Hello Mandeep,

    Can you please check below:

    Open sales order, Go to Invoices action and check whether any number (As given in error) is displayed.

    If there is no invoices there, Please go to Posted sales invoices and check by filtering the order number with the same order.

    Let us know.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: error while deleting sales order

    Hi All,

    Thanks for your support. I have tried to remove the order no and delete but it is not getting deleted as it is linked with no. series and PSS ,PSI(Posted Sales Shipment, Posted Sales Invoice). I have check the code as well all documents are interlinked. These sales orders are blank and are very old from the year 2013 to 2016 (6-7 sales orders) which I need to delete. Please advise.

    IF ("Document Type" = "Document Type"::Quote) AND ("Doc. Sub Type" = "Doc. Sub Type"::Quotation) THEN BEGIN

     IF ("Sent for Approval") AND (NOT Approved) THEN

       ERROR(Text5003,"Document Type","No.");

    END;

    IF DOPaymentTransLogEntry.FINDFIRST THEN

     DOPaymentTransLogMgt.ValidateCanDeleteDocument("Payment Method Code","Document Type",FORMAT("Document Type"),"No.");

    IF NOT UserSetupMgt.CheckRespCenter(0,"Res Center") THEN

     ERROR(

       Text022,

       RespCenter.TABLECAPTION,UserSetupMgt.GetSalesFilter);

    IF ("Opportunity No." <> '') AND

      ("Document Type" IN ["Document Type"::Quote,"Document Type"::Order])

    THEN BEGIN

     IF Opp.GET("Opportunity No.") THEN BEGIN

       IF "Document Type" = "Document Type"::Order THEN BEGIN

         IF NOT CONFIRM(Text040,TRUE) THEN

           ERROR(Text044);

         TempOpportunityEntry.INIT;

         TempOpportunityEntry.VALIDATE("Opportunity No.",Opp."No.");

         TempOpportunityEntry."Sales Cycle Code" := Opp."Sales Cycle Code";

         TempOpportunityEntry."Contact No." := Opp."Contact No.";

         TempOpportunityEntry."Contact Company No." := Opp."Contact Company No.";

         TempOpportunityEntry."Salesperson Code" := Opp."Salesperson Code";

         TempOpportunityEntry."Campaign No." := Opp."Campaign No.";

         TempOpportunityEntry."Action Taken" := TempOpportunityEntry."Action Taken"::Lost;

         TempOpportunityEntry.INSERT;

         TempOpportunityEntry.SETRANGE("Action Taken",TempOpportunityEntry."Action Taken"::Lost);

         PAGE.RUNMODAL(PAGE::"Close Opportunity",TempOpportunityEntry);

         IF Opp.GET("Opportunity No.") THEN

           IF Opp.Status <> Opp.Status::Lost THEN

             ERROR(Text043);

       END;

       Opp."Sales Document Type" := Opp."Sales Document Type"::" ";

       Opp."Sales Document No." := '';

       Opp.MODIFY;

       "Opportunity No." := '';

     END;

    END;

    SalesPost.DeleteHeader(

     Rec,SalesShptHeader,SalesInvHeader,SalesCrMemoHeader,ReturnRcptHeader,SalesInvHeaderPrepmt,SalesCrMemoHeaderPrepmt);

    VALIDATE("Applies-to ID",'');

    ApprovalMgt.DeleteApprovalEntry(DATABASE::"Sales Header","Document Type","No.");

    SalesLine.RESET;

    SalesLine.LOCKTABLE;

    WhseRequest.SETRANGE("Source Type",DATABASE::"Sales Line");

    WhseRequest.SETRANGE("Source Subtype","Document Type");

    WhseRequest.SETRANGE("Source No.","No.");

    WhseRequest.DELETEALL(TRUE);

    SalesLine.SETRANGE("Document Type","Document Type");

    SalesLine.SETRANGE("Document No.","No.");

    SalesLine.SETRANGE(Type,SalesLine.Type::"Charge (Item)");

    DeleteSalesLines;

    SalesLine.SETRANGE(Type);

    DeleteSalesLines;

    // 016 +++++++++++++

    IF ("Document Type" IN ["Document Type"::Quote,"Document Type"::Order]) THEN BEGIN

     //TESTFIELD("Lost Reason");

     // UPDATE STATUS ON LEAD

     IF (("Document Type" = "Document Type"::Quote) AND ("Doc. Sub Type" = "Doc. Sub Type"::Quotation))

       OR ("Document Type" = "Document Type"::Order) THEN BEGIN

       LeadHeader.RESET;

       LeadHeader.SETRANGE(LeadHeader."Document Type",LeadHeader."Document Type"::Quote);

       LeadHeader.SETRANGE(LeadHeader."No.","Lead No.");

       IF LeadHeader.FINDFIRST THEN BEGIN

          LeadHeader."Lost Reason" := "Lost Reason";

          LeadHeader.VALIDATE(LeadHeader."Followup Status",LeadHeader."Followup Status"::Lost);

          LeadHeader.MODIFY;

       END;

     END;

    END;

    // 016 *************

    SalesCommentLine.SETRANGE("Document Type","Document Type");

    SalesCommentLine.SETRANGE("No.","No.");

    SalesCommentLine.DELETEALL;

    GateEntryAttachment2.RESET;

    GateEntryAttachment2.SETRANGE("Source Type",GateEntryAttachment2."Source Type"::"Sales Return Order");

    GateEntryAttachment2.SETRANGE("Entry Type",GateEntryAttachment2."Entry Type"::Inward);

    GateEntryAttachment2.SETRANGE("Source No.","No.");

    IF GateEntryAttachment2.FINDFIRST THEN

     GateEntryAttachment2.DELETEALL;

    StrOrder.SETCURRENTKEY("Document Type","Document No.",Type);

    StrOrder.SETRANGE("Document Type","Document Type");

    StrOrder.SETRANGE("Document No.","No.");

    StrOrder.SETRANGE(Type,StrOrder.Type::Sale);

    IF StrOrder.FINDFIRST THEN

     StrOrder.DELETEALL;

    StrOrderLine.SETCURRENTKEY("Document Type","Document No.",Type);

    StrOrderLine.SETRANGE("Document Type","Document Type");

    StrOrderLine.SETRANGE("Document No.","No.");

    StrOrderLine.SETRANGE(Type,StrOrder.Type::Sale);

    IF StrOrderLine.FINDFIRST THEN

     StrOrderLine.DELETEALL;

    IF (SalesShptHeader."No." <> '') OR

      (SalesInvHeader."No." <> '') OR

      (SalesCrMemoHeader."No." <> '') OR

      (ReturnRcptHeader."No." <> '') OR

      (SalesInvHeaderPrepmt."No." <> '') OR

      (SalesCrMemoHeaderPrepmt."No." <> '')

    THEN BEGIN

     COMMIT;

     IF SalesShptHeader."No." <> '' THEN

       IF CONFIRM(

            Text000,TRUE,

            SalesShptHeader."No.")

       THEN BEGIN

         SalesShptHeader.SETRECFILTER;

         SalesShptHeader.PrintRecords(TRUE);

       END;

     IF SalesInvHeader."No." <> '' THEN

       IF CONFIRM(

            Text001,TRUE,

            SalesInvHeader."No.")

       THEN BEGIN

         SalesInvHeader.SETRECFILTER;

         SalesInvHeader.PrintRecords(TRUE);

       END;

     IF SalesCrMemoHeader."No." <> '' THEN

       IF CONFIRM(

            Text002,TRUE,

            SalesCrMemoHeader."No.")

       THEN BEGIN

         SalesCrMemoHeader.SETRECFILTER;

         SalesCrMemoHeader.PrintRecords(TRUE);

       END;

     IF ReturnRcptHeader."No." <> '' THEN

       IF CONFIRM(

            Text023,TRUE,

            ReturnRcptHeader."No.")

       THEN BEGIN

         ReturnRcptHeader.SETRECFILTER;

         ReturnRcptHeader.PrintRecords(TRUE);

       END;

     IF SalesInvHeaderPrepmt."No." <> '' THEN

       IF CONFIRM(

            Text055,TRUE,

            SalesInvHeader."No.")

       THEN BEGIN

         SalesInvHeaderPrepmt.SETRECFILTER;

         SalesInvHeaderPrepmt.PrintRecords(TRUE);

       END;

     IF SalesCrMemoHeaderPrepmt."No." <> '' THEN

       IF CONFIRM(

            Text054,TRUE,

            SalesCrMemoHeaderPrepmt."No.")

       THEN BEGIN

         SalesCrMemoHeaderPrepmt.SETRECFILTER;

         SalesCrMemoHeaderPrepmt.PrintRecords(TRUE);

       END;

    END;

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: error while deleting sales order

    Clear the posting No. from the header and then delete the order. If there is posting No. assigned on the header it will try to delete the invoice which is what causing the issue.

  • Suggested answer
    Tharanga Chandrasekara Profile Picture
    Tharanga Chandrasekara 23,116 on at
    RE: error while deleting sales order

    Agreed with others. It seems invoice has been created for the order. You can go to sales invoice page and check for the created invoice.

  • Suggested answer
    Alexander Ermakov Profile Picture
    Alexander Ermakov 28,094 on at
    RE: error while deleting sales order

    There is also Delete Invoiced Sales Orders Batch Job exists (msdn.microsoft.com/.../hh179047(v=nav.70).aspx)

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: error while deleting sales order

    Agree with [tag:Amol],

    use debugger and check where you get exception. you will get idea.

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: error while deleting sales order

    I think somebody has created sales invoice for this order . Kindly check.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,356 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans