Document Generation Tools
Document Generation fills a .docx or .xlsx template with the values of a record and attaches the result to that record. These tools manage the templates and produce the documents. The product also calls this feature "formatted export", which is the wording you see in server logs and URLs.
Available tools
| Tool | What it does |
|---|---|
anydb_list_docgen_templates | Lists the templates in a workspace with their id, name, the type they apply to, and the File record that holds the template file. |
anydb_create_docgen_template | Attaches an uploaded .docx or .xlsx file to a workspace type. |
anydb_update_docgen_template | Changes a template's name, type, or file. |
anydb_delete_docgen_template | Removes the template mapping. The uploaded file stays. |
anydb_generate_document | Generates a document from one record and attaches the result to it, optionally as a PDF or by email. |
Create a template
- Upload the template file with
prepare_file_upload, PUT the bytes, thencomplete_file_upload. See File tools. The upload must be completed: a File whose upload never finished is rejected. - Call
anydb_list_docgen_templatesto avoid creating a duplicate. - Call
anydb_create_docgen_templatewith the type'stemplateName, the File record's id asfileRecordId, and aname. The type must already exist.
A placeholder in the template is a field name in single braces, such as {Invoice Number}. This is not the double-brace {{...}} syntax of AnyDB formulas. A field can be named by its key or by its cell position, so {Invoice Number} and {B2} resolve to the same cell. A tag that names nothing renders empty instead of failing, so blanks in a generated document usually mean a placeholder does not match a field.
Update a template
anydb_update_docgen_template requires every field. The server removes and re-adds the entry, so anything you omit is lost and the entry comes back with a new id. List the templates again afterward instead of reusing the id you passed in.
Generate a document
anydb_generate_document takes the template id and the record. The result is an ordinary File record: pass the returned fileRecordId and cellPosition to download_file to fetch it.
Regenerating replaces: running the same template on the same record again supersedes the previous output instead of adding a second file. Replacement is per template, so generating a quote does not remove an invoice made from a different template on the same record.