Hi
If you leave those 2 fields blank when you insert the record the system will automatically fill them in
For it to work though you need to create and insert the new header (Insert), then populate the header fields and modify it, then insert and populate the lines
If you are creating everything in one go the lines wont see the header when they are inserted and you will have problems
That is the reason why codeunits are used even though they are more work, as you have complete control over how the records are inserted
You are correct though, adding the document and line numbers list that should work, however i think you will pick up other problems later due to this insert header first bit
Cheers
Nev