# Related List Structure In Microsoft Templates (DOCX, PPTX, XLSX)

When working with DOCX templates, related lists function similarly to standard S-Docs related lists, but with one key difference: DOCX templates require the use of tags to define where related list data begins and ends within Word tables. These tags allow S-Docs to correctly recognize, repeat, and format table rows inside a DOCX file, ensuring that related list records render properly in the generated document.

### Basic Structure:

```
[{{!<lineitemsSOQL>
<tableformat>]


//Your Table Here


[</tableformat>
<soql>select name, amount, description from opportunity order by id desc limit 30</soql>
<column>name</column>
<column>amount</column>
<column>description</column>
</lineitemsSOQL>}}]
```

{% stepper %}
{% step %}

#### 1. \[{{! and }}]

**Purpose**

S-Docs processing block markers

* `[{{!` tells S-Docs: *Start processing this block as S-Docs markup*
* `}}]` tells S-Docs: *Stop processing S-Docs markup*

They also appear as HTML comments so the content isn’t visible if the template is loaded elsewhere.
{% endstep %}

{% step %}

#### 2.

**Purpose**

This tells S-Docs to execute **Direct SOQL** — a runtime SOQL query — and render the results in the document.

Key traits:

* Runs a real SOQL query during **document generation**
* Not limited to objects related to the base record
* Useful for large datasets, filtering, grouping, and dynamic data retrieval

This is the core wrapper around your entire query block.
{% endstep %}

{% step %}

#### 3. and \[]

**Purpose**

Specifies where to place the table within the Word Document and how the table will be styled.

* Three requirements for the table in Microsoft Word
  * Header row with intended header text
  * Odd row with placeholder text for styling
  * Even row with placeholder text for styling
    {% endstep %}

{% step %}

#### 4.

**Purpose**

Defines the **exact Salesforce SOQL query** S-Docs should run.

Your example:

```
<soql>select name, amount, description from opportunity order by id desc limit 30</soql>
```

This retrieves:

* the 30 most recent Opportunities
* sorted by Id descending
* returning the fields: Name, Amount, Description

In a Direct SOQL block:

* `<soql>` overrides `<ListName>` and `<where>` if they exist
* It supports aggregates (`SUM`, `COUNT`), subqueries, GROUP BY, ORDER BY, etc.
* S-Docs merge fields can be included in SOQL queries

This is the heart of the data retrieval.
{% endstep %}

{% step %}

#### 5.

**Purpose**

Each `<column>` defines **one column** in the generated output table.

Example:

```
<column>name</column>
```

This tells S-Docs:

* For each row returned from the SOQL query
* Pull the `name` field
* Display it as a table column (in order listed)

**Columns must match the SOQL fields or aliases.**

For example:

```
<column>amount</column>
<column>description</column>
```

Optional attributes you could use:

* `format-number="#"`
* `format-date="M/d/yyyy"`
* `prefix="$"`
* `postfix=" units"`
* `replaceall="value1,replace1,value2,replace2"`
* `colspan="2"`

These control table layout and formatting.
{% endstep %}
{% endstepper %}

***

### Summary Table

| Tag                                                      | Meaning                                                   |
| -------------------------------------------------------- | --------------------------------------------------------- |
| <p><br><br>### <code>\[{{!</code> / <code>}}]</code></p> | S-Docs processing block markers                           |
| <p><br><br>### <code>\<tableformat></code></p>           | Tags for DOCX table creation                              |
| `<lineitemsSOQL>`                                        | Starts a Direct SOQL block (run real SOQL)                |
| `<class>`                                                | Styling for the generated table (use `none` for no table) |
| `<soql>`                                                 | The actual SOQL query S-Docs executes                     |
| `<column>`                                               | Defines each output column in the result table            |

### Full Example:

Literally the same as the Basic Structure.

```
[{{!<lineitemsSOQL>
<tableformat>]


//Your Table Here


[</tableformat>
<soql>select name, amount, description from opportunity order by id desc limit 30</soql>
<column>name</column>
<column>amount</column>
<column>description</column>
</lineitemsSOQL>}}]
```


---

# Agent Instructions: 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:

```
GET https://help.sdocs.com/developer-hub/template-configuration-and-styling/related-list-references/related-list-structure-docx.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
