Renaming File via Document Relationship - A journey

Hi Community,

Need some help here. I have a method to rename a file related to a document. The idea is that upon check-in the filename will update to the Doc Number + Name + Rev + Generation

It works for the most part but there are 4 errors depending on how this is implemented.

1. When set to OnBeforeLock/OnAfterLock, the code to define the string for the name only takes one of the values I added for concatenation and does not actually get the values from this.getProperty("item_number"), etc. so it ends up naming every file "v"

2. When set to OnAfterUpdate or OnAfterAdd I get an error when saving via the office connector, of note, OnAfterUpdate works fine when making an edit to the form, at that point the filename does get updated correctly: 

3. When set to OnAfterVersion, it works fine except when storing a document via the Office Connector...instead of replacing the files, it adds them to the previous versions. This causes problems. It also means the filename is not correct until the vile is versioned.

4. When set to OnBeforePromote/OnAfterPromote/OnBeforeAdd:

Help...