---
title: "SQL-025: Create DocumentTemplate via CreateTemplate"
summary: Create operation against DocumentTemplate via NHibernate ORM.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# SQL-025: Create DocumentTemplate via CreateTemplate

This ORM statement performs a create operation on `DocumentTemplate` via `CreateTemplate`, executed from `Services/SAIF.Services/Documents/TemplateSearchService.cs` (L413).

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-025 |
| **Operation type** | Create |
| **Execution method** | ORM (IRepository.Add) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `DocumentTemplate` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `CreateTemplate` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:Id` | Input | `long` | N/A | Identifier from `DOCUMENT_TEMPLATE_SEQ.NEXTVAL` |
| `:Name` | Input | `string` | N/A |  |
| `:Title` | Input | `string` | N/A |  |
| `:RunTemplate` | Input | `string` | N/A |  |
| `:RunRoutine` | Input | `string` | N/A |  |
| `:RunParameterFormName` | Input | `string` | N/A |  |
| `:NextDocTemplateSeqNum` | Input | `long?` | N/A |  |
| `:AdditionalPageNum` | Input | `long?` | N/A |  |
| `:BusinessGroup` | Input | `string` | N/A |  |
| `:Subgroup` | Input | `string` | N/A |  |
| `:IsEnabled` | Input | `bool` | N/A | Bound as `'Y'`/`'N'` (`YesNoType`) |
| `:EffectiveDate` | Input | `DateTime?` | N/A |  |
| `:ExpirationDate` | Input | `DateTime?` | N/A |  |
| `:NoteText` | Input | `string` | N/A |  |
| `:ImageFileCode` | Input | `string` | N/A |  |
| `:ImageCategoryCode` | Input | `string` | N/A |  |
| `:ImageDocumentTypeCode` | Input | `string` | N/A |  |
| `:ImageDocumentNameCode` | Input | `string` | N/A |  |
| `:ImageDocumentName` | Input | `string` | N/A |  |
| `:ImageIsRequired` | Input | `bool` | N/A | Bound as `'Y'`/`'N'` (`YesNoType`) |
| `:SharedMessage` | Input | `string` | N/A |  |
| `:MainBannerPageText` | Input | `string` | N/A |  |
| `:AdditionalBannerPageText` | Input | `string` | N/A |  |
| `:UpdateNumber` | Input | `int` | N/A |  |
| `:UpdateUser` | Input | `string` | N/A |  |
| `:UpdateDate` | Input | `DateTime?` | N/A |  |
| `:CreateUser` | Input | `string` | N/A |  |
| `:CreateDate` | Input | `DateTime?` | N/A |  |
| `:RunType` | Input | `RunTypeCode` | N/A | Identifier of the referenced `RunTypeCode` entity (`References(x => x.RunType)`) |
| `:ContextType` | Input | `ContextCode` | N/A | Identifier of the referenced `ContextCode` entity (`References(x => x.ContextType)`) |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [DOCUMENT_TEMPLATE](../database-tables.md#document_template) | INSERT | DOCUMENT_TEMPLATE_SEQ_NUM, TEMPLATE_NAME, TEMPLATE_TITLE, RUN_TEMPLATE_NAME, RUN_ROUTINE_NAME, RUN_PARAMETER_FORM_NAME, NEXT_DOC_TEMPLATE_SEQ_NUM, ADDITIONAL_PAGE_NUM, BUSINESS_GROUP_DESCRIPTION, SUB_GROUP_DESCRIPTION, ENABLED_FLAG, EFFECTIVE_DATE, EXPIRATION_DATE, NOTE_TXT, IMAGE_FILE_CODE, IMAGE_CATEGORY_CODE, IMAGE_DOCUMENT_TYPE_CODE, IMAGE_DOCUMENT_NAME_CODE, IMAGE_DOCUMENT_NAME, IMAGE_REQUIRED_FLAG, SHARED_MESSAGE_TXT, MAIN_BANNER_PAGE_TXT, ADDITIONAL_BANNER_PAGE_TXT, UPDATE_NUM, UPDATE_USER, UPDATE_DATE, CREATE_USER, CREATE_DATE, RUN_TYPE_CODE, CONTEXT_CODE (identifier from sequence `DOCUMENT_TEMPLATE_SEQ.NEXTVAL`) |

## LINQ statement

Source: `Services/SAIF.Services/Documents/TemplateSearchService.cs:413`.

```csharp
// Services/SAIF.Services/Documents/TemplateSearchService.cs:413
unitOfWork.GetRepository<DocumentTemplate>().Add(newTemplate);
```

## Sample SQL

> **Inferred SQL:** This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT DOCUMENT_TEMPLATE_SEQ.NEXTVAL
FROM DUAL

INSERT INTO DOCUMENT_TEMPLATE (
  DOCUMENT_TEMPLATE_SEQ_NUM,
  TEMPLATE_NAME,
  TEMPLATE_TITLE,
  RUN_TEMPLATE_NAME,
  RUN_ROUTINE_NAME,
  RUN_PARAMETER_FORM_NAME,
  NEXT_DOC_TEMPLATE_SEQ_NUM,
  ADDITIONAL_PAGE_NUM,
  BUSINESS_GROUP_DESCRIPTION,
  SUB_GROUP_DESCRIPTION,
  ENABLED_FLAG,
  EFFECTIVE_DATE,
  EXPIRATION_DATE,
  NOTE_TXT,
  IMAGE_FILE_CODE,
  IMAGE_CATEGORY_CODE,
  IMAGE_DOCUMENT_TYPE_CODE,
  IMAGE_DOCUMENT_NAME_CODE,
  IMAGE_DOCUMENT_NAME,
  IMAGE_REQUIRED_FLAG,
  SHARED_MESSAGE_TXT,
  MAIN_BANNER_PAGE_TXT,
  ADDITIONAL_BANNER_PAGE_TXT,
  UPDATE_NUM,
  UPDATE_USER,
  UPDATE_DATE,
  CREATE_USER,
  CREATE_DATE,
  RUN_TYPE_CODE,
  CONTEXT_CODE)
VALUES (
  :Id,
  :Name,
  :Title,
  :RunTemplate,
  :RunRoutine,
  :RunParameterFormName,
  :NextDocTemplateSeqNum,
  :AdditionalPageNum,
  :BusinessGroup,
  :Subgroup,
  :IsEnabled,
  :EffectiveDate,
  :ExpirationDate,
  :NoteText,
  :ImageFileCode,
  :ImageCategoryCode,
  :ImageDocumentTypeCode,
  :ImageDocumentNameCode,
  :ImageDocumentName,
  :ImageIsRequired,
  :SharedMessage,
  :MainBannerPageText,
  :AdditionalBannerPageText,
  :UpdateNumber,
  :UpdateUser,
  :UpdateDate,
  :CreateUser,
  :CreateDate,
  :RunType,
  :ContextType)
```

Translation notes:
- `:Id` is the value fetched from sequence `DOCUMENT_TEMPLATE_SEQ` (`GeneratedBy.Native("DOCUMENT_TEMPLATE_SEQ")`) before the INSERT; NHibernate assigns it to `DocumentTemplate.Id`.
- `:IsEnabled`, `:ImageIsRequired` are bound as `'Y'` / `'N'` (`YesNoType`).
- Reference FK values are bound from the associated entity's identifier; the referenced tables are **not** read or joined by this statement: `RunType` → `RUN_TYPE_CODE` (entity table `RUN_TYPE_CODE` not accessed); `ContextType` → `CONTEXT_CODE` (entity table `CONTEXT_CODE` not accessed).

## Operations and processes
- TemplateSearchService.CreateTemplate — see [Operations and processes](../operations-processes.md)

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- `Services/SAIF.Services/Documents/TemplateSearchService.cs (L413)`
