> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DEE template orders

> How to define and use DEE template orders with `{{placeholder}}` syntax, covering template registration through `addTemplateOrder`, execution through `submitTemplateOrders`, and placeholder substitution in MDX queries, filenames, and output columns.

A DEE template order defines placeholders using `{{ }}` syntax that are substituted with values at submission time.

## Template orders

DEE supports order templates. These templates are DEE Orders that can be pre-configured with placeholders, which can be filled in when executing the template order. Compared to a normal DEE Order, a template can contain placeholders that will be replaced by values provided at execution time.

The placeholders in the template order follow the below format:

```
{{placeholder_key}}
```

### Template orders structure

Template orders have a `name` element, which corresponds to the `templateOrderName` path parameter of the PUT request when registering the template order.

Additionally, template orders have a `priority` element, a `queries` array, and an `output` element.

#### Priority

The default priority is `NORMAL`. The following priorities are listed in order of highest priority to lowest priority:

1. `EXCEPTIONAL`
2. `CRITICAL`
3. `VERY_HIGH`
4. `HIGH`
5. `NORMAL`
6. `LOW`
7. `VERY_LOW`

#### Queries

Within the queries array, there is one element with a `type` element, such as a `GetAggregatesQuery` query.

For example, a `GetAggregatesQuery` query describes the cube the query will be run against with the element: `pivotId`, the levels in the query in
the element: `locations`, and the measures included in the query in the element: `measureSelections`.

For more information, see [Extraction Queries](/overview#extraction-queries).

#### Output

Output elements include `filenameRoot` for output sub-directory and file name,
`extractionProcedure` for using custom extraction procedures, and lastly the `columns` array, describing where each column will get its data.

Template placeholders can also be used. Placeholders are defined in the template orders within the special characters `{{` and `}}`. For example,
the order can contain an MDX query with an `{{AS_OF_DATE}}` placeholder. Then when the template order is executed, a value can be specified for the `AS_OF_DATE`
placeholder.

For more information, see [DEE Order Attributes](/user-guide/dee-orders#dee-order-attributes).

##### Output sub-directory and file name

The `filenameRoot` element sets the subdirectory and the file name.

##### Columns

The `columns` element describes how output columns will be populated.

The output file's columns map to one of the following types:

* Level (`levelOutputColumn`)
* Measure (`measureOutputColumn`)
* Static value (`echoOutputColumn`)
* Value which requires some logic (`extractProcValueOutputColumn`)

## Executing template orders

### Register template order

Template Orders can automatically be registered by adding the Template Order JSON file into the `data.extraction.templates.base.dir.path` directory.

Alternatively, the following services expose methods to add, update, and remove a template:

* `addTemplateOrder/{orderName}` - Registers the [JSON DeeOrder](./dee-order-structure/overview) provided in the REST body.
* `removeTemplateOrder/{orderName}` - Removes a template order with the provided name.

Below is an example of registering a template order through the REST services:

#### URL

```
.../connectors/rest/dee/VERSION/addTemplateOrder/MyNewTemplateOrder
```

#### JSON PUT body

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
  "name": "Any_Order_Name",
  "maxMdxNbRetries": 2,
  "priority": "NORMAL",
  "queries": [
    {
      "@type": "MdxQuery",
      "mdx": "select * from [cube] where {{MDX_FILTER_PLACEHOLDER}}"
    }
  ],
  "output": {
    "@type": "fileOutput",
    "columns": [
      {
        "@type": "levelOutputColumn",
        "dimensionName": "dim1",
        "hierarchyName": "hier1",
        "levelName": "lvl1"
      },
      {
        "@type": "measureOutputColumn",
        "name": "measure1",
        "format": "{{FORMATTER_PLACEHOLDER}}",
        "valueIfNull": "N/A"
      }
    ]
  }
}
```

This example includes a placeholder in the MDX statement as well as in the Formatter of the measure output column.

Read more about [DEE Order Schema](./dee-orders#order-structure).

### Executing template orders

Template orders can be executed by calling the `/submitTemplateOrders` endpoint and sending the JsonTemplateOrder object as seen below:

#### URL

```
.../connectors/rest/dee/VERSION/submitTemplateOrders
```

#### JSON POST body

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
  "templateOrderName": "MyNewTemplateOrder",
  "templatePlaceholders": {
    "MDX_FILTER_PLACEHOLDER": "Date=Today",
    "FORMATTER_PLACEHOLDER": "##.##"
  }
}
```
