taking a glance at this thread, I want to make this remark
you can use a trigger and generator to have a unique identifier for your record, but not at the same time for your document.
for your record, you will have to accept gaps.
for your document, define another generator specific to your document, and coherent with your new record; that will garantuee you consistent documentnumbers
grts,
guido