> For the complete documentation index, see [llms.txt](https://docs.agilecase.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agilecase.com/administrator-documentation/templates/creating-a-document-template-with-table-custom-fields.md).

# Creating a Document Template with Table Custom Fields

This lesson will show you how to set up a document template to include a custom field table. Before trying this, you should know how to create a simple document, which you can learn [here](/administrator-documentation/templates/creating-a-simple-document-template.md).

### Custom field tables

<figure><img src="/files/PFvRIxWaTq2k4eeAxyKx" alt=""><figcaption></figcaption></figure>

In AgileCase, it is possible to set up tables of custom fields within a case. To learn how to do this, follow [this](/administrator-documentation/case-type-settings/creating-case-custom-fields.md) lesson.

Like any other field, these tables can be exported to a document using a template. However, the process is a little more complicated than with standard fields.

{% stepper %}
{% step %}

### Locate the table in the Merge Field Helper

<figure><img src="/files/TGuxkY20aWzAkTRcOA15" alt=""><figcaption></figcaption></figure>

On the merge field helper for the case, find the field table you want to add to the template. It will be prefixed with the element `<Case.Custom.Table. (name of the table)>`.

These fields are the ones you will use to create your table in the template.
{% endstep %}

{% step %}

### Create a table in Word and enter your mergefields

<figure><img src="/files/C05kcQkdWgwkRxdaV1Z7" alt=""><figcaption></figcaption></figure>

To ensure the table is properly formatted in the resulting document, create a table in Word and populate it with your mergefields.

When creating a table, you must create two additional mergefields: one at the start of the table and one at the end.

At the start, create a mergefield:

`{MERGEFIELD TableStart:(name of the table)}`

At the end, create a mergefield:

`{MERGEFIELD TableEnd:(name of the table)}`

This will signal to the system that you are creating a table and will cause it to populate a row of information for each entry.

{% hint style="danger" %}
The screenshot above shows mergefields that have been copied out of AgileCase. These include the entities `Case.Custom.Table`. These should be deleted when they have been copied across and should not be included if you are writing your own mergefields.
{% endhint %}

To create these mergefields:

1. Press `Alt+F9` to activate Mail Merge mode.
2. Press `Ctrl+F9` to insert a Mail Merge field. You will know this is successful when a set of squiggly brackets `{ }` appears.
3. Type `MERGEFIELD` in capitals before entering the details of the field in the exact format above.

Please note that mergefields are case sensitive, so ensure that the element in the document is in the correct format.

Mergefields must be updated after you edit them. To do this, right-click on the mergefield and select **Update Field** to save the changes you have made.

Place these fields in the same column as your first field, before the fields, and in the same column as your last field, after the field.

Copy the other mergefields in the table into the appropriate column without modification. If you want to use table headings, create a two-row table and enter the headings in the top row above the appropriate mergefield.
{% endstep %}

{% step %}

### Create your document as normal

<figure><img src="/files/6YgrWpYp4wEnIGy73k1I" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/8XsBYS6slE09ep4aVVRk" alt=""><figcaption></figcaption></figure>

Create a document and select your template containing the custom field table.
{% endstep %}

{% step %}

### View your formatted table

Your table will appear as you set it up in the template, with a row for each entry you have made in the field table in AgileCase.
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.agilecase.com/administrator-documentation/templates/creating-a-document-template-with-table-custom-fields.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
