Skip to content

Generate documents with input variables

The Generate Document action creates a draft from a Document template and replaces the template’s input-variable tokens with workflow data. Use it for reports, summaries, confirmations, handover packs, and any document whose structure stays stable while its values change.

First prepare the template in the Documents module. Build reusable documents with input variables covers definitions, tokens, defaults, and the Include input variables template option.

The process has four parts:

  1. A Document template declares input variables such as customer_name and total_due.
  2. A workflow receives data from its trigger, workflow variables, or earlier action outputs.
  3. Generate Document maps those workflow values to the template’s variable names.
  4. Automation creates a new draft document with the tokens resolved.

Document input variables and workflow variables are related but different. A workflow variable is mutable state used while the workflow runs. A document input variable is a contract defined by the selected template. The Generate Document mapping connects the two.

  1. Create or open a workflow in the same service as the document template.
  2. Convert the workflow to Free Form.
  3. Add and configure a trigger with representative test data.
  4. Add any Create Variable, Update Variable, Transform, or data actions needed to prepare the values.
  5. Add Generate Document from the Platform action category.
  6. Connect the preceding action’s success output to Generate Document.

Free Form requires explicit connections. Placing the action beside another step does not make it run after that step.

Open the Generate Document configuration and select Template. The picker is scoped to templates available to the workflow’s service, including built-in system templates. A private template from another service is not available.

The workflow must be saved with a service before the picker can load templates. You can also enter a template ID or expression in the alternate template field, but the selected template must still be available to the same service at runtime.

When you select a template, Generate Document reads its input-variable definitions and creates a named binding field for each one. Each binding shows:

  • the variable’s label, or its name when no label was provided;
  • an asterisk when the variable is required;
  • its description; or
  • the {{variable_name}} token and type when no description was provided.

Changing the selected template rebuilds the declared binding list. Values for names shared by both templates are retained; unrelated custom mappings remain in Additional mappings.

Each binding accepts literal text, inserted expressions, or a mixture of both. Use the expression builder beside the field to choose a trigger value, workflow variable, or earlier action output.

Examples:

{{ variables.customer_name }}
Invoice {{ variables.invoice_number }} — {{ outputs.calculate_total.value }}

Prefer the expression builder over typing paths from memory. It inserts the action and property names that are actually available at that point in the workflow.

Source Use it when Typical expression shape
Trigger context The value arrived with the event that started the run. {{ ctx.customer.name }}
Workflow variable A Create Variable or Update Variable step prepared the value. {{ variables.customer_name }}
Action output A previous action calculated, filtered, queried, or transformed the value. {{ outputs.previous_action.result }}
Literal or mixed text The value is fixed or needs a fixed prefix or suffix. Account {{ variables.account_id }}

Mappings are resolved when Generate Document executes, after the current branch, loop, parallel group, or try/catch context has been assembled. That lets a binding use outputs produced earlier in the same execution path.

Generate Document resolves each declared variable in this order:

  1. use the mapped value when it is not empty;
  2. otherwise use the template’s non-empty default;
  3. otherwise fail when the variable is required; or
  4. leave it unresolved when the variable is optional.

The configuration drawer prevents saving when a required binding is visibly empty and has no mapped value. Runtime validation performs the same protection after expressions resolve.

Variable type Runtime behavior
Text Used as supplied.
Number Converted to a finite number. Non-numeric input fails the action.
Boolean Accepts booleans plus true, false, 1, or 0. Other values fail the action.
Date, URL, email, color, image Passed through as supplied. Use the expected format because these types describe the template contract but are not reformatted by Generate Document.

An empty string counts as missing. A numeric zero and boolean false are real values and do not trigger the default.

Add a mapping not declared by the template

Section titled “Add a mapping not declared by the template”

Choose Add Mapping to add a key and value manually. Additional mappings are useful for:

  • a legacy template containing {{token}} placeholders but no variable definitions;
  • a token intentionally excluded when the template was saved; or
  • an extra key used inside nested template data.

The mapping key must exactly match the text between the braces. A manually added customer_name mapping replaces {{customer_name}}; it does not replace {{customerName}}.

Declared bindings are preferable because they carry labels, types, descriptions, defaults, and required-state validation.

Document title also accepts free text and expressions. Give each generated document a useful, searchable name:

Account report — {{ variables.customer_name }} — {{ variables.report_date }}

When no title is supplied, Automation creates one from the template name and current date.

Generate Document walks the saved template data and replaces every matching token once.

  • If a field contains only {{total_due}}, a number remains a number and a boolean remains a boolean.
  • If a token appears inside a longer string, the result is text.
  • Objects and arrays inserted into longer text are serialized as JSON rather than [object Object].
  • A mapped value containing its own {{...}} text is treated as data and is not evaluated a second time.
  • An unknown token remains visible, which makes missing or misspelled mappings easy to spot in the generated draft.

Enable Export PDF when a later action needs the generated document as a file attachment. Generate Document still creates the draft document and also attempts a PDF export.

The action returns these main fields:

Output Meaning
documentId ID of the new draft document.
documentName Resolved document title.
createdAt Creation timestamp.
sectionCount Number of template sections copied.
templateId / templateSource Template used and whether it came from the visual template catalogue or a legacy document.
assetId Asset Library record registered for the new document, when registration succeeds.
pdfGenerated / pdfUrl PDF result when export is enabled.
file / attachment The generated PDF attachment descriptor.
attachments A list containing the PDF attachment, ready for a downstream action that accepts attachments.

Use the expression builder in an Email or other downstream action to select Generate Document’s attachments output. When Export PDF is off, file and attachment are null and attachments is empty.

A PDF export failure does not remove the newly created document. Inspect pdfGenerated and pdfError when the workflow must distinguish document creation from attachment creation.

Assume the selected template declares customer_name, report_date, total_due, and approved.

  1. Manual Trigger supplies a representative customer record.

  2. Create Variable creates customer_name from the trigger.

  3. Transform actions calculate total_due and format report_date.

  4. Update Variable stores the final values when later steps also need them.

  5. Generate Document binds:

    Template input Workflow value
    customer_name customer-name workflow variable
    report_date Format Date result
    total_due calculation result
    approved literal false or an approval output
  6. Enable Export PDF when the next Email action should attach the report.

  7. Connect Generate Document to the downstream action and select its attachment output with the expression builder.

Keep the workflow as a draft while testing. Use representative values for every declared type, then inspect the Generate Document step in Run history.

Confirm that:

  • the resolved input contains the expected mapping values;
  • a new draft document appears in the same service;
  • the title and every visible token are resolved;
  • numeric and boolean fields retained the intended type;
  • the output contains documentId and assetId when registration succeeded; and
  • attachments contains one item when PDF export was enabled.

Run separate checks for a missing optional value, a required value, a default, numeric zero, boolean false, and a malformed number. Creating a document is a real side effect, so use a test service or remove test drafts after review.

The template was probably saved without Include input variables, or the workflow still has an older template selection cached. Re-save the document as a template with the toggle enabled, then reselect the template in Generate Document.

Check that the mapping key and token match exactly, including capitalization. Also confirm that the expression resolved to a value. An undeclared optional token with no additional mapping remains unchanged.

A required input fails even though the field contains an expression

Section titled “A required input fails even though the field contains an expression”

The expression resolved to an empty string, null, or an unavailable path. Inspect the preceding step’s output in Run history and reinsert the correct property with the expression builder.

Confirm that the document was saved as a template in the workflow’s service. Templates private to another service are deliberately hidden.

The document was created but there is no attachment

Section titled “The document was created but there is no attachment”

Confirm Export PDF was enabled, then inspect pdfGenerated and pdfError. Document creation and PDF generation are separate stages.