Error while posting a Warehouse shipment

poppinspoppins Member Posts: 647
edited 2015-01-04 in NAV Three Tier
Hi everyone,
I am trying to post a Warehouse shipment an getting the following error:
An attempt was made to change an old version of a Sales Line record. The record should first be reread from the database. This is a programming error.

Identification fields and values:

Document Type='Order',Document No.='1339',Line No.='10000'
While debugging, the debugger points at the following line,
      IF ModifyLine THEN
        SalesLine.MODIFY;
What can possibly cause that?

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Do you have any customization which is modifying sales line record before this code?
  • poppinspoppins Member Posts: 647
    Do you have any customization which is modifying sales line record before this code?
    It's standard code in codeunit 5763:
    WITH WhseShptLine DO BEGIN
      SalesLine.SETRANGE("Document Type","Source Subtype");
      SalesLine.SETRANGE("Document No.","Source No.");
      IF SalesLine.FIND('-') THEN
        REPEAT
          SETRANGE("Source Line No.",SalesLine."Line No.");
          IF FIND('-') THEN BEGIN
            IF "Source Document" = "Source Document"::"Sales Order" THEN BEGIN
              SumOfQtyToShip := 0;
              SumOfQtyToShipBase := 0;
              GetATOAndNonATOLines(ATOWhseShptLine,NonATOWhseShptLine,ATOLineFound,NonATOLineFound);
              IF ATOLineFound THEN BEGIN
                SumOfQtyToShip += ATOWhseShptLine."Qty. to Ship";
                SumOfQtyToShipBase += ATOWhseShptLine."Qty. to Ship (Base)";
              END;
              IF NonATOLineFound THEN BEGIN
                SumOfQtyToShip += NonATOWhseShptLine."Qty. to Ship";
                SumOfQtyToShipBase += NonATOWhseShptLine."Qty. to Ship (Base)";
              END;
    
              ModifyLine := SalesLine."Qty. to Ship" <> SumOfQtyToShip;
              IF ModifyLine THEN BEGIN
                SalesLine.VALIDATE("Qty. to Ship",SumOfQtyToShip);
                SalesLine."Qty. to Ship (Base)" := SumOfQtyToShipBase;
                IF ATOLineFound THEN
                  ATOLink.UpdateQtyToAsmFromWhseShptLine(ATOWhseShptLine);
                IF Invoice THEN
                  SalesLine.VALIDATE(
                    "Qty. to Invoice",
                    SalesLine."Qty. to Ship" + SalesLine."Quantity Shipped" - SalesLine."Quantity Invoiced");
              END;
            END ELSE BEGIN
              ModifyLine := SalesLine."Return Qty. to Receive" <> -"Qty. to Ship";
              IF ModifyLine THEN BEGIN
                SalesLine.VALIDATE("Return Qty. to Receive",-"Qty. to Ship");
                IF Invoice THEN
                  SalesLine.VALIDATE(
                    "Qty. to Invoice",
                    -"Qty. to Ship" + SalesLine."Return Qty. Received" - SalesLine."Quantity Invoiced");
              END;
            END;
    
            IF SalesLine."Bin Code" <> "Bin Code" THEN BEGIN
              SalesLine."Bin Code" := "Bin Code";
              ModifyLine := TRUE;
              IF ATOLineFound THEN
                ATOLink.UpdateAsmBinCodeFromWhseShptLine(ATOWhseShptLine);
            END;
          END ELSE BEGIN
            ModifyLine :=
              ((SalesHeader."Shipping Advice" <> SalesHeader."Shipping Advice"::Complete) OR
               (SalesLine.Type = SalesLine.Type::Item)) AND
              ((SalesLine."Qty. to Ship" <> 0) OR
               (SalesLine."Return Qty. to Receive" <> 0) OR
               (SalesLine."Qty. to Invoice" <> 0));
    
            IF ModifyLine THEN BEGIN
              IF "Source Document" = "Source Document"::"Sales Order" THEN
                SalesLine.VALIDATE("Qty. to Ship",0)
              ELSE
                SalesLine.VALIDATE("Return Qty. to Receive",0);
              SalesLine.VALIDATE("Qty. to Invoice",0);
            END;
          END;
          IF ModifyLine THEN
            SalesLine.MODIFY;
        UNTIL SalesLine.NEXT = 0;
    END;
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    I don't think it will be a standard error.
    Can you replicate it in standard demo database?
  • skullaskulla Member Posts: 140
    Check if you have customization before you call posting codeunit which will modify sales line or any modifications in the sales line table itself which recursively modify the record on validation of certain fields.
  • poppinspoppins Member Posts: 647
    skulla wrote:
    Check if you have customization before you call posting codeunit which will modify sales line or any modifications in the sales line table itself which recursively modify the record on validation of certain fields.
    If so, how can I correct the error??
  • skullaskulla Member Posts: 140
    One way to do is issue COMMIT statement when you call post codeunit if the modify happens before posting, if the modify is during the validate of a sales line field i.e recursive then your need to refactor you code so that it does not execute MODIFY function.

    Please use COMMIT statement with caution.
Sign In or Register to comment.