Temporary ID for draft documents

At the moment, a doc id like an invoice number is saved at the first save.
To realize a currently analogue (MS Office + printing) workflow in ERPnext, I need to be able to set the invoice number after submitting the invoice finally and before I want to give it a temporary ID.
Is there a built in way to achieve this?
If not: Does someone have an idea on how to achieve this?

In my opinion you should consider changing your workflow to match that of the document naming (UID creation). For example if you aren’t using sales order, you can start all transactions as sales order, then convert to sales invoice when you are ready for the invoice number to be written to the database.

Failing that, the only thing I can think of is to create a custom field like mydocid. I’m not sure how or if you’ll be able to use the built-in naming series/automation function. You can create a custom script and perhaps a button to create mydocid prior to submitting it. You can set the field as unique and in your script have it set to required prior to submission.

Alternatively, if you insist on your workflow

  1. Assign “Random” or any other naming option / serie to your Invoice.
  2. Create a server script that triggers on submit to Rename Doc (see below)

To properly handle renaming

  1. Create a tabSingles doctype to store your index number.
  2. In your server script get the value stored in the above created doctype using get_single_value
  3. Use the fetched value in your formulated naming series (i.e., INV-xx)
  4. After successful renaming, increment the value.
  5. Save both documents, no need to db commit in server scripts.