At five documents a month nobody automates anything: open the card, click Create document, download, send. At fifty the picture changes — an invoice goes out carrying last year's number, a contract leaves a blank line where the bank account should be, and "which invoice covered this deal?" takes a minute of digging. Here is how to put generation on rails in Bitrix24 (Alaio): where the number comes from, who clicks the button instead of the sales rep, and where the finished file ends up.
Where do a deal's documents live?
Documents sit on their own tab inside the card, next to activities and products. The create button is right there: pick a template, the platform merges in the deal data, both parties' details and the product rows, and hands back a docx and a pdf. The templates themselves live in CRM settings, where they are uploaded, edited and bound to sections — some become available in invoices, others in deals or estimates. How a template is built — merge fields, modifiers, the table part — is covered in document templates; this article is about everything that happens around the generation.
How does document numbering work?
The number comes from a numerator: a set of rules the platform follows to assemble the string. You configure it in CRM under More → Settings → CRM settings → Numerator, or directly in the document template form. Separate numerators can be set for documents, invoices and estimates; leads and deals use standard numbering that cannot be changed.
The number is built from parts: a prefix (INV, DOC), the current day, month or year, a sequential number, a random combination, the record ID, or your company ID. The sequential part takes a starting value, a step, a length and a filler character — that is how you get "0042" instead of "42". The setting that matters most is the period: continuous, or reset within a day, a month or a year. With a yearly period the counter goes back to one on 1 January, and "INV-2027-0001" happens on its own. Whether numbering runs across all of your companies or restarts per company is a separate switch.
If the number has to exist in the card as well as in the file — for filters, search, or handing to an external system — write it into a deal field with Update deal by ID. A readable number can also be assembled from values you already store by the Field template field: a pattern like INV-{ID}-{YEAR} is rendered right in the card, no workflow involved.
How to generate a document automatically at a stage?
The Documents group of automation rules includes a stock Create document rule: the deal reaches a stage, the document builds itself. Its settings cover the template, the company and its details, values for the document fields, plus the options "wait for PDF conversion to finish" (needed when a later rule works with the pdf link), "with signature and stamp", and "create public link".
A stage is not the only sensible trigger. A contract is best prepared the moment every required field is filled rather than when someone remembers; an invoice, once the approval is done. The branch itself is built with an if-then condition, and the approval route is laid out in invoice approval. The wider picture of what fires when lives in the workflow automation guide.
How to avoid generating a document with empty fields?
A template does not argue: no bank account on file means a blank space in the contract, and that blank goes to the customer. Put a check in front of the generation. The Field is not empty robot returns Y/N for any field on the card — amount, due date, signatory — and several checks fold into one condition. Everything present: the document is generated. Something missing: the process assigns a task to the deal owner and stops. That single check saves more time than any template ever will, because reissuing a signed contract costs more than an hour of delay.
How to prepare values before the template runs?
Some values a template cannot produce; they have to be computed first and stored in fields. Format a date puts the date into the shape the document needs: {D} gives "2 September 2026", {d.m.Y} gives "02.09.2026". Format a number fixes thousands separators and decimal places so the invoice reads "1,250,000.00" rather than "1250000". Each result is written into a deal field and then merged into the template like any other field — which also means the same value appears in filters and exports, not only inside the file.
What to do with the generated file?
The file is in the card, but a process usually needs more than that. Get file URL from CRM card pulls the direct download link out of a file field, ready to be emailed or handed to an external system. Public link to a Drive file produces a link a customer can open with no portal access at all. Count files in a field checks a set is complete: fewer than two files in the field means the closing package is short, and the process reminds accounting. And a signed scan coming back from an external service is filed into the card by Download file from URL and attach. How file fields behave in the first place is covered in the File field.
What next
Start with the number: set up a numerator with a yearly reset and write the number into a deal field — that alone answers half of the "which invoice was that?" questions. Then add the check before generation, and only after that hang a rule on the stage. Back-filling the deals you already have is a job for bulk workflow launch, and pulling documents into a spreadsheet for accounting is covered in exporting CRM data. The remaining blocks live in the robot catalog and the field catalog. If the one you need is missing, describe the task: we build missing activities for free and ship them to the shared library.