# Adding DMS Tab to a Module

### 1. Add xModule-Control to the new created Tab&#x20;

![Design Mode](/files/-MXlBDzzTDke3Gsr-8al)

![](/files/-MXlBIcVLfIIwClYVTMI)

XAML Code:

```markup
<tl:xDockTabItem Header="DMS" Name="tabDMS" Uid="4352f300-c8a7-430f-a10a-bd291d2a3de6" IsEnabled="False">
    <tl:xGrid Uid="d68e9eec-9a33-4eae-96ab-d8884dae960d">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <tl:xModule Name="xModDMS" Grid.Row="0" Grid.Column="0" ModuleID="modDMS3" IsEnabled="True" />
    </tl:xGrid>
</tl:xDockTabItem>
```

### 2. Initialize and load DMS Control

```csharp
public xModule DmsModule
{
    get
    {
        return this.GetControlByNameAndTyp<xModule>("xModDMS");
    }
}

public IxDmsModule DmsControl
{
    get
    {
        if (DmsModule == null) return null;
        return DmsModule.ModuleWHO as IxDmsModule;
    }
}
```

```csharp
public virtual void InitDms()
{            
    if (DmsControl != null)
    {
        DmsControl.Init(hybrid, "proz_charg");
    }
}
```

For newly created tables or hybrids, the connection between the DMS-tables and the current table will be done by creating a SQL Command for inserting a new record in dms\_class, dms\_categories, dms\_tree and dms\_treepos.

<pre class="language-sql"><code class="lang-sql">$START
-- create the dms class
if not exists (select * from dms_class where id = 'my_dms_class') then
    insert into dms_class("id", "matchcode", "default_category")
    values ('my_dms_class', 'My-Class', null)
endif;
 
-- create a dms category for the class and set it as default
if not exists (select * from dms_categories where class='my_dms_class') then
    insert into dms_categories (id, class, matchcode, default_arch_type, default_arch_zeitraum, hybrid)
    values ((select max(id) from dms_categories) + 1, 'my_dms_class', 'Standard', null, null, 'DMS_CATEGORY^'||(select max(id) from dms_categories) + 1);
    update dms_class set default_category=(select max(id) from dms_categories)
    where id='my_dms_class';
endif;
 
--create a dms tree for the class
if not exists (select * from dms_tree where ref_hybrid='my_dms_class') then
    insert into dms_tree (nr, "type", ref_hybrid)
    values (((select coalesce( max(nr), 1) from dms_tree) + 1), 1, 'my_dms_class')
endif;
 
-- create a tree root node for the class as well as a default folder
if not exists(select * from dms_treepos where treenr = (select nr from dms_tree where ref_hybrid = 'my_dms_class') and handle = 0) then
    insert into dms_treepos (treenr, handle, lnode, rnode, "info", dms_class_id, typ, hybrid)
    values ((select nr from dms_tree where ref_hybrid = 'my_dms_class'),0,1,4,'My-Class','my_dms_class',10,'DMS_TREEPOS^'||CAST((select nr from dms_tree where ref_hybrid='my_dms_class') AS INTEGER)||'^0');
    insert into dms_treepos (treenr, handle, lnode, rnode, "info", dms_class_id, dms_categories_id, typ, hybrid)
    values ((select nr from dms_tree where ref_hybrid = 'my_dms_class'),1,2,3,'Standard','my_dms_class',(select default_category from dms_class where "id"= 'my_dms_class'), 20,'DMS_TREEPOS^'||CAST((select nr from dms_tree where ref_hybrid='my_dms_class') AS INTEGER)||'^1');

<a data-footnote-ref href="#user-content-fn-1">-------------------------------------------OPTIONAL--------------------------------------------------</a>
-- create the virtual node for emails
    insert into dms_treepos (treenr, handle, lnode, rnode, "info", dms_class_id, dms_categories_id, typ, content_type, hybrid)
    values ((select nr from dms_tree where ref_hybrid = 'my_dms_class'),2,4,5,'E-Mails','my_dms_class',(select default_category from dms_class where "id"= 'my_dms_class'), 20, 10, 'DMS_TREEPOS^'||CAST((select nr from dms_tree where ref_hybrid='my_dms_class') AS INTEGER)||'^2');
-------------------------------------------------------------------------------------------------------------------
endif;

$ENDE
</code></pre>

If you need to add the E-Mails folder to an already existing hybrid dms tree, use the following script:

```sql
$START
IF NOT EXISTS (SELECT 1 FROM dms_treepos where content_type=10 AND treenr=(SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class')) THEN 
    INSERT INTO dms_treepos (treenr, handle, hybrid, lnode, rnode, "info", dms_class_id, dms_categories_id, typ, content_type)
    VALUES 
    (
        (SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class'),
        (SELECT max(handle)+1 FROM dms_treepos WHERE treenr=(SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class')),
        (string('DMS_TREEPOS^',(SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class'),'^',(SELECT max(handle)+1 FROM dms_treepos WHERE treenr=(SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class')))),
        (SELECT lnode+2 FROM dms_treepos WHERE treenr=(SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class') AND handle=1),
        (SELECT rnode+2 FROM dms_treepos WHERE treenr=(SELECT nr FROM dms_tree WHERE ref_hybrid='my_dms_class') AND handle=1),
        'E-Mails',
        'my_dms_class',
        (SELECT default_category FROM dms_class WHERE "id"='my_dms_class'), 
        20, 
        10
    );
    UPDATE dms_treepos SET rnode=rnode+2 WHERE treenr=(select nr from dms_tree where ref_hybrid='my_dms_class') AND handle=0;
END IF;
$ENDE
```

[^1]: If an email folder is required for the class created above, please execute the following statement. You may skip this step for classes that do not require an email folder.


---

# 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://tldocs.gitbook.io/documentation/framework/window-handling-object/adding-dms-tab-to-a-module.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.
