---
title: "Document Generation"
url: "https://docs.signnow.com/docs/hubspot-document-generation"
type: "page"
section: "Integrations"
slug: "hubspot-document-generation"
---

# Document Generation

# Document generation

Document generation in HubSpot allows users to generate documents pre-filled with data from a HubSpot record using a .docx template with tags. With a document flow and a custom action, a user generates the document and sends it for signature in one click, straight from a Contact, Deal, or Company.

The tag types described in this article (data tags, system tags, and fillable-field tags) follow the general SignNow document generation syntax. For the full reference, see the [SignNow document generation guide](/docs/document-generations).

## Before you start

- Make sure you have admin access to **SignNow Admin Tools**.
- Prepare a .docx file to use as the template.
- Decide which HubSpot object you will send from (Contact, Deal, or Company). The object you send from determines which data the tags can pull, so choose it before you add tags.

## How it works

- Prepare a .docx template with tags.
- Upload the template in **Admin Tools** > **Document Generation**.
- Optionally, create a document flow to define recipients and invite settings.
- Create a custom action that generates the template and sends it for signature.
- On the record, a user clicks the custom action button to generate and send the document in one click.

## Prepare the template

Add tags to your .docx file. When the document is generated, each tag is replaced with the matching value from the HubSpot record, or turned into a fillable field for a recipient to complete.

A tag is text wrapped in double braces, for example `{{dealname}}`.

> Tag names (the text inside the braces) can contain only letters, numbers, dots, and underscores. A name cannot include spaces, cannot start with a number or a dot, and cannot end with a dot. HubSpot API internal names already follow these rules, so you can use them as they are (see [Find a field's API name](/docs/hubspot-document-generation#find-a-fields-api-name)).

### Data tags: pre-fill from HubSpot

Data tags pull values from the HubSpot object you send from and its related objects.

#### Own fields of the object you send from

Write the field name on its own, with no object prefix. For example, when the document is generated from a Deal:

```
{{dealname}}
{{amount}}
{{closedate}}
```
---

#### Fields from a related object

Reach a related object's field with dot notation, using the object name followed by the field name. For example, from a Deal you can pull the associated company and contact:

```
{{Companies.name}}
{{Companies.city}}
{{Companies.zip}}
{{Contacts.firstname}}
{{Contacts.email}}
```

**Example of data tags**

<!--
focus: center
bg: none
-->

![hubspot_docgen_related_fields.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_related_fields.png)

---

#### Line items

Line items belong to the Deal, so the itemized table resolves only when the document is generated from a Deal. Build the table with a `table` tag: put the opening `{{table(line_items)}}` tag, the row of item fields, and the closing `{{endtable}}` tag on separate table rows. The item fields are written flat inside the table:

```
{{table(line_items)}}
{{name}}   {{quantity}}   {{price}}   {{amount}}   {{recurringbillingfrequency}}
{{endtable}}
```

At generation time, SignNow repeats the middle row (the one with the field tags, between `{{table(line_items)}}` and `{{endtable}}`) once for each line item on the Deal. So a Deal with four line items produces four rows in the table.

Learn more about [table tags](/docs/document-generations#generate-a-dynamic-table).

**Example of line items tags**


<!--
focus: center
bg: none
-->
![hubspot_docgen_line_items.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_line_items.png)


### Find a field's API name

> Field names are HubSpot API internal names. They are lowercase and case-sensitive, so copy them exactly.


To copy the exact internal name of any HubSpot field:

- Open the HubSpot **gear icon** (Settings).
- Go to **Data Management** > **Properties**.

![hubspot_docgen_data_management.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_data_management.png)

- Select the object (for example, Deals or Companies).
- Search for the property you want.
- Open the property and copy its **Internal name**.

![hubspot_docgen_internal_field_name.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_internal_field_name.png)

Use that internal name inside the tag.

> Line items do not appear in the Properties object dropdown. To find a line item field's internal name, add `{{toJson($sysConstants)}}` to the template and generate it once from a Deal, then read the field keys inside the `line_items` array. Common defaults are `name`, `price`, `quantity`, `amount`, `recurringbillingfrequency`, and `hs_sku`.

### System tags: dates and formatting

- `{{$today}}` inserts the current date (MM-DD-YYYY).
- `{{$sumabove}}` adds up the numeric column above it, which is useful for a total row under the line-items table.
- `{{numFormat(amount, ‘$#,###.00’)}}` formats a number as currency.

> **Important**: `numFormat` requires Word-style curly quotes around the format string (`‘$#,###.00’`). Straight quotes will not work and the value will not be formatted. Type the tag in Word so it applies smart quotes automatically, or paste the curly quotes in.

### Fillable-field tags: fields recipients complete

Fillable-field tags create empty fields for recipients to fill in the generated document. They do not pull HubSpot data. Use straight quotes here.

- Signature: `{{t:s;r:y;o:"Role";}}`
- Text or date: `{{t:t;r:y;o:"Role";l:"Label";}}`
- Checkbox: `{{t:c;r:n;o:"Role";}}`

`r:y` marks the field required, `r:n` optional. The value in `o:"Role"` maps to a recipient role in the document flow.

> Fillable-field tags accept both single-brace (`{...}`) and double-brace (`{{...}}`) syntax. All other tags must use double braces.

Learn more about [fillable field tags](/docs/document-generations#fillable-field-tags).

> **Tip**: Place each fillable-field tag on its own line, in a single uniform format, and type it in one pass.

**Example of fillable field tags**

![hubspot_docgen_fillable_fields.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_fillable_fields.png)

### Check your tags before you publish

To confirm the exact field and relation names available for your object, add `{{toJson($sysConstants)}}` anywhere in the template and generate the document once. It prints the full payload with every available key and value, so you can copy names verbatim. Remove this tag before you use the template for real, since it dumps raw data into the document.

## Upload the template

- In HubSpot, open **Go to Admin Tools** and select **Document Generation**.
- Click **Upload .docx Template**.
- Select your tagged .docx file.

![hubspot_docgen_upload_ready.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_upload_ready.png)

The template appears in the list with its Name, ID, Last Modified date, and Status.

> The **Status** column reflects the tag check. **Ready** means the tag syntax passed validation and the template can be sent. **Failed** means there is a problem in the tags to fix before sending.

If the Status is **Failed**, the template has tag errors and cannot be sent, and a **View errors** button appears next to it. Click **View errors** to open **Fix syntax errors in template**, which lists what to correct. Select **Copy error details** to copy the full list, fix the tags in your .docx file, then upload it again.

## Create a document flow (optional)

A document flow defines recipients, signing order, and the invite email for the generated document. Creating one is optional, but it lets you preset recipient roles and a branded invite so the sender does not configure them each time.

To create one, open **Admin Tools** > **Document Flows** and follow the steps in [Document Flows](/docs/hubspot-admin-tools#document-flows).

> When setting up the flow, make sure the recipient roles you define match the roles used in your template's fillable-field tags (the `o:"Role"` value).

## Create a custom action to generate and send

A custom action adds a button to a HubSpot record that generates the template and sends it for signature in one click. Create it in **Admin Tools** > **Custom Actions** using the general steps in [Custom Actions](/docs/hubspot-admin-tools#custom-actions).

For a document generation action, set it up as follows:

- For the document source, select **SignNow template: pre-selected by the Admin**, then select your document generation template.

![hubspot_docgen_custom_template.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_custom_template.png)

- Optionally, add the document flow you created above.
- For **Object**, select the HubSpot object where the button appears and the document is sent from. The template can use this object's own fields and fields from objects related to it, such as the associated company or its line items.

![hubspot_docgen_custom_object.png](/reference-assets/images/SignNow_Hubspot/hubspot_docgen/hubspot_docgen_custom_object.png)

> Make sure the selected object matches the object used in the template and the document flow.

> Because line items belong to the Deal, a template with a line-items table must use Deals.

## Generate and send from a record

Open the HubSpot record for the object the action was created on (for example, a Deal). On the SignNow card, click your custom action button (for example, **Generate and send agreement**).

SignNow generates the document from the template and pre-fills it with the record's data.

The document is delivered for signature according to your document flow.

To follow the document after it is sent, see [Track Documents](/docs/hubspot-track-documents).


---
*Full page: https://docs.signnow.com/docs/hubspot-document-generation*
