RE: Auto Numbering of a Custom Field
First option that requires no planning for concurrency is to create a custom record type that uses auto numbering and creates a new custom record for every invoice and use its name as your custom field’s value
Second option that requires planning for concurrency is to use a custom record to store the next number you want to assign in a custom field. Load that custom record, get its number, update the old one by 1, save the custom record, then set your custom fields number to the number from the custom record. Expect to learn from the SAFE guide how to handle concurrency to handle cases where 2 invoices are created at the same time.