Change Line No. in Sales Order Line

I have tried the RENAME option but get a system error message to say it is not possible to change the record.

I am now trying the following:

(Processing only report with filters, oldsalesline is temp table)

SalesLine.GET(“Document Type”,“Document No.”,“Line No.”);

oldsalesline := salesline;

SalesLine.delete;

salesline.TRANSFERFIELDS(oldsalesline);

salesline.“line no.” := NewLineNo;

salesline.INSERT(TRUE);

However, all that happens is the original line number is deleted.

Is there a simpler and working method to change the line no. please?

Rename seems to have been disabled for the sales line table, probably because there is too much stuff that could go wrong due to links to the sales line table. I would say it depends on how far the sales line is processed would determine whether you want to do something drastic like commenting out that error message. Then again, if you have a brand new sales line that has not been processed at all, recreating the line probably does exactly the same.

In your code, make sure that you are using the right variables. It looks like you use ‘salesline’ to GET, then copy to ‘oldsalesline’ and then you use ‘salesline’ to insert a new one. If I were to program that, I would use ‘salesline’ to GET and then I would use one called ‘newsalesline’ to build a new one. Semantics though, it should really do the same, but that’s how it makes sense to me.

Why are you trying to change the number anyway?

The user has been reversing shipped lines, then shipping and unshipping many times and now NAV in not able to insert a new line when unshipping for the 4th or 5th time.

Thanks, this worked. At least for inserting a copy with a new line number. I still need to see what damage it may have done as the posted sales shipment and the linked drop shipment will not be connected now.

More work to do but at least I have a solution to the first bit.

SalesLine.GET(“Document Type”,“Document No.”,“Line No.”);

OldSalesLine := SalesLine;

OldSalesLine.“Line No.” := NewLineNo;

SalesLine2.TRANSFERFIELDS(OldSalesLine);

SalesLine2.INSERT(TRUE);

SalesLine.DELETE;

Right you got the point. No need for 3 variables though, try this:

SalesLine.GET(“Document Type”,“Document No.”,“Line No.”);
NewSalesLine := SalesLine;
NewSalesLine.“Line No.” := NewLineNo;
NewSalesLine.INSERT(TRUE);
SalesLine.DELETE;

Colin you really can’t do this. The issue (Daniel was on the right track) is that “line” tables in general that relate to items do not have table links, for example reservation, planning, manufacturing, tracking, warehouse and other tables simply have a link to a type, sub type and doc number. You would have to go through every table that has a link to the sales line and manually write code to fix the links.

Even some things that are linked, like GetShipments, wont handle a salesline.delete(false), so you could have sales invoice lines that can\t be posted or deleted, same goes for drop ships and special orders.

It may look like you are close to a solution the way you are going, but you are not even 10% there, and that other 90% is the bit that is going to cost the time.

My recommendation would be to find the code that inserts the “undo shipment line” and change the Line number at that point before any validation. Of hand I think it does something like NewLineNo := (Nextline - Lastline) / 2 + LastLine, so in the middle. Change that code to Newline := LastLine + 1;

Grab a copy of Nav US and look at how they do the line numbers in Kitting Boms.

Thanks David, good advice.

There are other problems with the user doing multiple ship/unship, the SO line ends up with the wrong quantity to invoice.

I have a feeling that I am going to have to sort out a few other issues yet.

If I were you I’d figure out the other issues before this RENAME workaround.

David’s suggestion of changing the code (Codeunit 5815) to add 1 (or more) to the calculation works correctly. many thanks David!

You are welcome,

Great to hear it works.