Skip to main content
Our app needs two custom objects: document templates (what to write) and documents (the generated result). Let’s define them. Scaffold each entity file with the CLI — it generates a valid UUID and the right folder for you:
Below we show the finished files.
Every *_UNIVERSAL_IDENTIFIER constant lives in src/constants/universal-identifiers.ts and is imported where used. The snippets below omit those imports for brevity — keep them in your own files.

The template object

A template has a name, a body with {{placeholders}}, and a target that says whether it’s written for a Person or a Company. The body is a RICH_TEXT field, so Twenty gives it a full rich-text editor.
SELECT option values must be UPPER_CASE (PERSON, not person), and the defaultValue is wrapped in extra quotes: `'PERSON'`. The label is what users see.

The document object

The generated document stores the rendered content and a status. Define it the same way, with a status select of DRAFT / GENERATED. Full file: document.object.ts.

Linking them with a relation

Each document should point back to the template it came from. Relations are bidirectional — you define both sides, each in its own field file.
The other side (template-documents-relation.field.ts) is a RelationType.ONE_TO_MANY field named documents that points the opposite way. See Relations for the full pattern.

See it in Twenty

With yarn twenty dev running, open Settings → Data model. Both objects appear, tagged with your app.
Data model settings showing Documents and Document templates

Both custom objects, owned by the Document Generator app.

Create one template to test with — name it Sales proposal, set Target to Person, and paste a body with a few placeholders:
A Sales proposal template record with placeholder body

A template record. The body keeps its placeholders until a document is generated.

After this step: you have documentTemplate and document objects, linked by a relation, and one template to generate from. Next, the logic that fills it in.

Next: generating documents →

Write the logic function that fills the template.