> ## 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.

# Add custom limit structure templates

> How to add custom limit structure templates in Atoti Limits to pre-populate fields when creating limit structures in the UI, using LimitStructureTemplateConfigurationProperties in application.yml or Spring bean configuration

When creating a new limit structure via the UI, you can pre-populate fields with default values from a custom template.
This can be useful when creating limit structures that share common attributes.

## How it works

To create your own template, you will need to create a bean of the `LimitStructureTemplate` class. Note that the `templateName` and `serverName` fields are required:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
@Data
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
public class LimitStructureTemplate {

  // The name of the template - must be unique
  @NonNull private String templateName;

  // The server this template belongs to - required
  @NonNull private String serverName;

  // LimitStructure fields that can be templated
  protected String group;
  protected String name;
  protected String comment;
  protected KpiType kpiType;
  protected PollingFrequency pollingFrequency;
  protected String measureName;
  protected boolean absoluteValueIndicator;
  protected int warningThreshold;
  protected String exceptionWorkflow;
  protected String limitChangesWorkflow;
  protected String cubeName;
  protected String utilizationDashboardID;
  protected List<String> scopeKeys;
  List<LimitWorkflowDetails> limitWorkflowDetails;
}
```

### Define the beans

To define a `LimitStructureTemplate` bean, you have two options:

#### Option 1 (Recommended): Define a set of `LimitStructureTemplateConfigurationProperties` in `application.yml`

`LimitStructureTemplates` can be created via configuration properties. This is the recommended approach as it allows you to define multiple templates in a single file and have the Spring beans created automatically.

To define a template in `application.yml`, add the description under the `limits.structure.templates` property. A minimal template can be defined as follows, where `MyConnectedServer` is the name of the Atoti Server that Limits will connect to and serves as the key in the map:

```yaml theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
limits:
  structure:
    templates:
      MyTemplate:
          template-name: MyTemplate
          server-name: MyConnectedServer
```

A more complex example can define default values for all configurable fields of a `LimitStructure` for multiple templates:

```yaml theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
limits:
  structure:
    templates:
      MyTemplate1:
        template-name: MyTemplate1
        server-name: MyConnectedServer
        group: Group1
        name: LimitStructure1
        comment: This is a comment
        kpi-type: GREATER
        polling-frequency: EOD
        measure-name: PnL
        absolute-value-indicator: true
        warning-threshold: 0
        exception-workflow: Exception
        limit-changes-workflow: StraightThrough
        cube-name: MyConnectedServerCube
        utilization-dashboard-id: 5b4
        scope-keys:
          - Book@Books@Booking
      MyTemplate2:
        template-name: MyTemplate2
        server-name: MyConnectedServer
        group: Group2
        name: LimitStructure2
        comment: This is another comment
        kpi-type: LESS
        polling-frequency: EOD
        measure-name: PnL
        absolute-value-indicator: false
        warning-threshold: 0
        exception-workflow: Exception
        limit-changes-workflow: Six-Eyes Approval Process
        cube-name: ConnectedAccCube
        utilization-dashboard-id: 9d1
        scope-keys:
          - ID@Trades@Trades
        limit-workflow-details:
          - workflow-name: Six-Eyes Approval Process
            business-functions:
              - Limit Changes
            variables:
              - name: Comment
                type: TEXT
              - name: Initial Attachment
                type: ATTACHMENTS
              - name: First Approvers
                type: SELECT
                options:
                  - ROLE_USERS
                  - ROLE_MANAGERS
                default-value: ROLE_USERS
              - name: Second Approvers
                type: SELECT
                options:
                  - ROLE_USERS
                  - ROLE_MANAGERS
                default-value: ROLE_MANAGERS
```

#### Option 2: Define a `LimitStructureTemplate` bean in a configuration class

To define your own template, add a method in any `@Configuration` class. Annotate the method with `@Bean` and return a `LimitStructureTemplate` object.
See [Importing Spring Beans into the Project](.#importing-spring-beans-into-the-project) for more information.

Example:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
@Bean
public LimitStructureTemplate myTemplate() {
  return LimitStructureTemplate.builder()
    .templateName("My Template")
    .serverName("My Server")
    .group("My Group")
    .name("My Name")
    .comment("My Comment")
    .kpiType(KpiType.LESS)
    .pollingFrequency(PollingFrequency.MINUTE)
    .measureName("My Measure Name")
    .absoluteValueIndicator(true)
    .warningThreshold(10)
    .exceptionWorkflow("My Exception Workflow")
    .limitChangesWorkflow("My Limit Changes Workflow")
    .cubeName("My Cube Name")
    .utilizationDashboardID("My Utilization Dashboard ID")
    .scopeKeys(List.of("My Scope Key"))
    .build();
}
```

### Use the template

Once you have defined your template beans, they will be available for selection in the UI when creating a new limit structure. For more details, see [Using limit structure templates](../../user-ref/using-limits/create-limit/create-limit-ui#using-limit-structure-templates).
