Writing register records from 1C:Enterprise script
If you run the Write() method of the document object, the document is written without involving the document form. This means that the BeforeWrite event of the document form is never called and so the handler script is never executed.
To synchronize the period of document register records with the document date in the scenario where the document is written using 1C:Enterprise script tools, you have to use the BeforeWrite event handler of the document object instead of the BeforeWrite handler of the document form.
During interactive document writing the BeforeWrite event of the document form is called first, and then the BeforeWrite event of the document object is called (see the chart of events in section Event sequence for writing documents from document forms).