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 :
Microsoft Dynamics NAV (Archived)

An attempt was made to change an old version of a “Sales Line” record

(1) ShareShare
ReportReport
Posted on by 3,013

So I'm working on NAV 2017, using advanced warehouse functionality:

- I create a sales order and add an item line quantity: 4 

- I create a warehouse shipment for this sales order

- I create a warehouse pick and do a partial pick, so I put Qty. to Handle: 1 and register my pick

- Now when I try to register send only my Warehouse Shipment, I get this error:

"An attempt was made to change an old version of a “Sales Line” record"

Debug and see that standard code is throwing this. The call stack is basically:

CU 80 Post calls FinalizePosting ->  PostUpdateOrderLine(SalesHeader); -> ModifyTempLine(TempSalesLine);

The code in ModifyTempLine is standard:

TempSalesLineLocal.MODIFY;
SalesLine := TempSalesLineLocal;
SalesLine.MODIFY; //This Line throws error

I modified this function to see if any customizations (which I'm almost sure, I don't have in this part) could be the problem, but I still get the error:

COMMIT;
TempSalesLineLocal.MODIFY;
SalesLine.GET(TempSalesLineLocal."Document Type",TempSalesLineLocal."Document No.",TempSalesLineLocal."Line No.");
SalesLine := TempSalesLineLocal;
SalesLine.MODIFY; //Still throws the error

*This post is locked for comments

I have the same question (0)
  • ManishS Profile Picture
    86 on at

    First of all you should not use commit.

    Sounds a bug to me, cause if you try to modify the current rec system through this error.

    Try using a different variable and modify the record.

  • Ghetz Profile Picture
    3,013 on at

    Even without COMMIT I get the same error. Also sounds looks like a bug to me, but nothing se can control at Code level.

    Also thought about database snapshot isolation configuration, but seems like NAV is not affected by this setting.

  • Ghetz Profile Picture
    3,013 on at

    It doesn't really make sense. 

    If I change the code to this, I don't get any error. 



    LOCAL ModifyTempLine(VAR TempSalesLineLocal : TEMPORARY Record "Sales Line")
    TempSalesLineLocal.MODIFY;
    SalesLine.GET(TempSalesLineLocal."Document Type",TempSalesLineLocal."Document No.",TempSalesLineLocal."Line No.");
    SalesLine."Outstanding Quantity" := TempSalesLineLocal."Outstanding Quantity";
    SalesLine."Quantity Shipped" := TempSalesLineLocal."Quantity Shipped";
    SalesLine."Qty. Shipped (Base)" := TempSalesLineLocal."Qty. Shipped (Base)";
    SalesLine."Qty. to Ship"  := TempSalesLineLocal."Qty. to Ship";
    SalesLine."Qty. to Ship (Base)" := TempSalesLineLocal."Qty. to Ship (Base)";
    SalesLine."Outstanding Qty. (Base)" := TempSalesLineLocal."Outstanding Qty. (Base)";
    SalesLine."Qty. Shipped Not Invoiced" := TempSalesLineLocal."Qty. Shipped Not Invoiced";
    SalesLine."Qty. Shipped Not Invd. (Base)"  := TempSalesLineLocal."Qty. Shipped Not Invd. (Base)" ;
    SalesLine.MODIFY;

    So, why can I assign individual fields and then MODIFY the record, but record := temprecord throws error. Also tried SalesLine.COPY(TempSalesLineLocal) and SalesLine.TRANSFERFIELDS(TempSalesLineLocal) 

    Both throw errors. For the momento, I'm going to have to manually copy all the affected fields, but I would like the standard code to work.

    Any ideas?

  • Suggested answer
    Zaid Tariq Profile Picture
    2,274 on at

    Hi,

    As far as i know you cannot use COPY and and TRANSFERFIELDS function is the record is of type Temp.

    This not actually possible in NAV record := temprecord;

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    Hello Ghetz,

    When you use

    SalesLine := TempSalesLineLoca;

    SalesLine.MODIFY;

    There is a risk that you change the primary key. When you change a primary key it is a RENAME not a MODIFY.

    Try this

    TempSalesLineLocal.MODIFY;
    
    IF SalesLine.GET(TempSalesLineLocal.RECORDID) THEN
    
     SalesLine.DELETE(TRUE);
    
    SalesLine.INIT
    
    SalesLine := TempSalesLineLocal;
    
    SalesLine.INSERT(TRUE);


    The second code you say it works... it works because you use GET before (SalesLine := TempSalesLineLocal has nothing to do with the error).

  • Ghetz Profile Picture
    3,013 on at

    OK.. but.. does this mean the original code by Microsoft is bugged?

    Actually I don't see any risk of primary key modification. The Sales Line primary key is Type, Document No. and Line No.   This fields never change. They have the same value in TempSalesLineLocal and in the actual record.

    I find it risky to delete de original sales Line.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Did you or anyoneelse find any solutions?

    I am struggling With same fault...

    I hav used lot of time to find solutions but not succseed.

  • martin1116 Profile Picture
    5 on at

    I used a dumb way to fix this. I went to the table field list and copied them all to Excel. Then I set SalesLine.field := TempSalesLineLocal.field on all fields except the primary key. Concatenated everything, and copied it back to codeunit 80. Worked fine so far.

  • Community Member Profile Picture
    on at

    We got exactly the same issue with Dynamics NAV 2018 in Cumulative Update 2.

    The same Code is in Codeunit 90, too.

    Hopefully Microsoft will fix this issue.

  • Community Member Profile Picture
    on at

    Try

    RealRec.TRANSFERFIELDS(TempRec,FALSE);

    This worked for me in similar situation. FALSE here means do not change source's primary key.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans