How to delete a sales ordre with associated purchase order

lagersjeflagersjef Member Posts: 57
Hi,

--Using NAV 4.0 SP2--

My issue is that I am not allowed to delete a sales order because a sales line on the order is referring to a purchase order.

Steps to reproduce:
1. Create a sales order
2. Add an item to a sales line
3. Create a purchase order
b. refer the purchase order to the sales line just created

4. Try to delete the sales order. You will get a message saying:
You cannot delete the order line because it is associated with purchase order %1 line %2.

5. Next thing I do is to delete the purchase order. This goes well

6. Then I try to delete the sales order again, but still get the same message

7. I go into the Object designer and run the Sales Line table and see that there is still a reference to the purchase order that no longer exist. From here, I am not allowed to delete the reference either

Does anyone have any tips for how I can delete the sales order?

I have been looking for a concatenation table between the sales line and purchase order table, but cannot seem to find it.

Any help appreciated!

Comments

  • SavatageSavatage Member Posts: 7,142
    the fields are probably not visible on the sales line but they exist.

    if you click on a slaes line & ZOOM you will see the PO# & PO line No filled.
    You need to clear those fields (if they are not editable, make them) then you can delete.
  • lagersjeflagersjef Member Posts: 57
    I saw the fields with zoom and also directly in the table through object designer. I am however not allowed to delete the value. The purchase order is just a look-up field (got an Up-arrow right of the field) in the Sales Line table
  • matttraxmatttrax Member Posts: 2,309
    We have this problem all the time. We buy parts for a customer and then they say they don't need it.

    Instead of making the fields editable (I don't like changing field definitions back and forth), just write a report / codeunit, set your filters, assign values to the fields, and modify the records. Works like a charm every time.
  • SavatageSavatage Member Posts: 7,142
    If this is something you're going to do on a regular basis how about a Command Button on the Sales Header call it ClearPO or something.
    Example/
    Text Constant - Question - Would you like to Clear the Purchase Order Fields?

    OnPush()
    IF NOT DIALOG.CONFIRM(Question,TRUE) 
     THEN EXIT
     ELSE
      SalesLine.RESET;
      SalesLine.SETRANGE("Document Type","Document Type");
      SalesLine.SETRANGE("Document No.","No.");
      IF SalesLine.FIND('-') THEN
        REPEAT
        ClearPurchaseLineSO;
        ClearSalesLinePO;
        UNTIL SalesLine.NEXT = 0;
    

    ClearSalesLinePO()
    CLEAR(SalesLine."Special Order Purchase No.");
    CLEAR(SalesLine."Special Order Purch. Line No.");
    CLEAR(SalesLine."Purchase Order No.");
    CLEAR(SalesLine."Purch. Order Line No.");
    SalesLine.MODIFY(TRUE);
    

    ClearPurchaseLineSO()
    IF Purchline.GET("Document Type",SalesLine."Special Order Purchase No.",SalesLine."Special Order Purch. Line No.")
     THEN BEGIN
      CLEAR(Purchline."Special Order Sales No.");
      CLEAR(Purchline."Special Order Sales Line No.");
      Purchline.MODIFY(TRUE);
    END;
    

    I'm clearing the SPECIAL order purchase no - but assign the field that you are filling if it's different.

    NOTE this is good for completely clearing ALL links not just 1 line
  • lagersjeflagersjef Member Posts: 57
    Thanks the quick and good help!

    I'll give this a try and revert with the results
Sign In or Register to comment.