Today I would like to briefly share an error handling of Business Central. I was asked this question again recently.
Have you ever experienced the following two errors?
1. When adding a new line, such as adding a new Sales Line.
The line cannot be split.
2. When you undo a posted document, such as undo posted sales shipment.
There is not enough space to insert correction lines.
Both errors are standard errors in Business Central. And it causes them all for the same reason.
If you try to debug, the first error (The line cannot be split.) is thrown by the platform and isn’t written in any code, so debugging doesn’t stop at the error. As for the second error (There is not enough space to insert correction lines.), Microsoft has optimized the error handling message to make the system throw an error that is easier to understand, so this can be caught by debugging.
As shown in the debugging result above, this is caused by Line No.. But why?
Here I would like to mention an interesting automatic numbering feature in Business Central.
AutoSplitKey Property: Sets whether a key is automatically created for a new record placed between the current record and the previous record.
To set this property to a value of true, the following conditions must be met:
- The current key must be the primary key.
- The last field in the primary key must be an Integer Data Type, BigInteger Data Type, GUID Data Type, or Decimal Data Type field.
For example, in page 46 “Sales Order Subform”:
In page 39 “General Journal”:
With this property set, when adding a new record, numbers are automatically assigned in 10000, 20000, 30000, 40000 …. in increments of +10000.
For example, Line No. is 20000.
Add a new line.
So what if a new line is added between lines 20000 and 30000?
The line No. will be 25000.
If you continue to add new lines above, the number will be automatically assigned according to the following rules: 25000 -> 22500 -> 21250 -> 20625 -> 20312 -> 20156 -> 20078 -> 20039 -> 20019 -> 20009 -> 20004 -> 20002 -> 20001 -> Error (The error occurred after adding 13 times in the same direction)
Of course, this does not mean that you can only insert 13 times between two lines. But remember that adding new lines between two lines is not unlimited.
This is the same in Posted Sales Shipment, because when you undo the posted sales shipment, the system will automatically insert a new line with a quantity of -1. If the line number is no longer available, an error will be prompted.
At this point you may realize that if we use the system normally, these two errors should rarely occur. Yes, but if the partner customizes to create data in the code or import data using Configuration Package, it may cause this problem.
For example, only add 1 to the Line No. in the code or Excel. I’ve encountered it several times.😑
So if you add 10000 between each line, there will be no problem. This is the same as the standard processing.
What should we do if we have encountered this problem?
1. Insert new lines at the end of the page.
2. In order to avoid this kind of problem with the posted data, you can delete all lines and re-enter or import.
Hope this will help.
Thanks for reading.