What’s the problem?
You are running a Microsoft Dynamics 365 Business Central report or action that needs to read Sales Lines and it stops with an error – “Sales Header does not exist. Identification fields and values: Document Type=’Order’, No.=’SO107######'”
In our case, we were running Suggest Worksheet Lines from Cash Flow Forecast Worksheet including Sales Orders.
Not a regular occurrence
You have been working just fine in BC, and it doesn’t make sense. How can it give an error including a document number telling us the document number does not exist? Thankfully, from experience, I knew exactly what was happening. Somehow, some way we had an “orphaned” Sales Line. Don’t get me wrong, I don’t know how we had an orphaned sales line, I just know we did.
I have yet to see something like this caused by standard functionality. This customer does have several extensions installed. I am not pointing fingers, but I also don’t want anyone thinking they are going to end up with orphaned records on a regular basis, because most everyone will never encounter this problem. But if you do, here is a quick tip that will in most cases take care of it and without a developer’s help.
Let’s get this fixed
The first thing you are going to want to do is look at the Document No. in the error message to determine the source. In our example, this document number is assigned to Sales Orders. Next, we go to No. Series and find the No. Series assigned to Sales Orders. We need to check to make sure we can assign Manual Numbers. If not, we temporarily provide this ability by checking Manual Nos. for Sales Order No. Series.
Now we need to create a new sales order and use the number in our error message for the No. If you had to change your No. Series setup to allow Manual Nos., you will notice a difference when you create a new sales order. The No. field is now available for entry at the top of the General FastTab. Enter the Document Number found in the error.
Here’s where the “magic” happens. Go down to the Lines FastTab and you should find at least one line even though you didn’t enter any lines. This is the “orphaned” line that generated our error message. BC was letting us know this line was missing it’s header. In our case, it is an empty Comment Type line and actually hard to identify because other than Line Type it looks empty. Since we have “Item” set as our Default Line Type, I knew this line was real and our culprit.
Now that we have reunited our orphaned Sales Line with its parent Sales Header, all we need to do is delete the Sales Order. The child will follow the parent away – as it should!
Testing the results
After deleting the Sales Order, we went back to our Cash Flow Forecast Worksheet and suggested lines again. It worked! Problem solved.
Don’t forget to undo your No. Series setup
If you had to enable Manual No. on your Sales Order No. Series, don’t forget to go back and uncheck/disable it again.
If this doesn’t work
If this trick doesn’t work, you may be able to do something with a Configuration Package or get a developer’s help. But, I can tell you that whenever I had this issue back in Dynamics NAV and most recently (for the very first and only time) in Business Central, this trick has worked for me. It may work for you and for any document type that has a header/line data structure.
You may never need this, but…
You will probably never run into this error. But if you do, you now know at least one trick to fix it.