Skip to main content

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​

ToolWhat it does
anydb_list_docgen_templatesLists 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_templateAttaches an uploaded .docx or .xlsx file to a workspace type.
anydb_update_docgen_templateChanges a template's name, type, or file.
anydb_delete_docgen_templateRemoves the template mapping. The uploaded file stays.
anydb_generate_documentGenerates a document from one record and attaches the result to it, optionally as a PDF or by email.

Create a template​

  1. Upload the template file with prepare_file_upload, PUT the bytes, then complete_file_upload. See File tools. The upload must be completed: a File whose upload never finished is rejected.
  2. Call anydb_list_docgen_templates to avoid creating a duplicate.
  3. Call anydb_create_docgen_template with the type's templateName, the File record's id as fileRecordId, and a name. 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.