# Data Connection

Komment allows for three different methods to be used when saving data.&#x20;

### QIX Engine

> Utilizes the built-in QIX Engine API for processing the writing mechanism. Partial reload is performed by the Qlik Sense user.

{% hint style="warning" %}
Does not support Qlik Analyzer license&#x20;
{% endhint %}

### Kaptain

Kaptain is an added service that you can purchase to enhance the functionality of Komment. There are several reasons as to why Kaptain might be relevant for you:

{% hint style="success" %}
You have a need for **SQL DB storage** of saved data => Kaptain enables writeback to external databases. We currently support MS SQL, MySQL, PostgreSQL, Oracle DB, Snowflake & MongoDB.
{% endhint %}

{% hint style="success" %}
You have a high number of **concurrent users** using Komment => Kaptain can handle high concurrency cases (i.e. several users saving comments at the same time)
{% endhint %}

{% hint style="success" %}
You will use Komment in **larger** Qlik applications (+200 mb) => Kaptain **increases performance** to near **real time** save and hence, better handling of large Qlik applications.
{% endhint %}

{% hint style="success" %}
You require **dynamic** updates to Komment data model to be possible => Kaptain allows for dynamic updates to Komment data model **without breaking** with historic data structure - i.e. you can freely add new data entry fields to your existing Komment objects.
{% endhint %}

{% hint style="success" %}
You have **Analyzer** licenses => Kaptain enables Analyzer users to store data using Komment
{% endhint %}

{% hint style="success" %}
You want to be prepared for the **future** => Kaptain will soon make it possible to connect your Qlik Sense apps with many **external services** which expands the possible use cases for Komment
{% endhint %}

Just contact us if you would like to add Kaptain to your Qlik Sense writeback solution.

### Comparison

| Feature/Element                               | QIX engine | Kaptain |
| --------------------------------------------- | :--------: | ------- |
| Security rule setup needed                    |     Yes    | No      |
| Each user must have ‘CommentingRole’ assigned |     Yes    | No      |
| Concurrency handling                          |     No     | Yes     |
| Supporting Analyzer License users             |     No     | Yes     |
| Extra node.js service to be installed         |     No     | Yes     |
| Partial reload needed when saving data        |     Yes    | No      |

### Kaptain Configuration

The setup is made in the Data Connection Settings section. The default is QIX Engine so if you don't have a plan (Standard, Pro or Premium) where Kaptain Service is included you don't have to touch this section.

1. Select your Connection Type
2. Input the URL to Kaptain service
   1. If you have multiple environments (devl, test, prod, etc.) you can ease the setup by defining a variable that holds the URL

   2. Then you just reference this variable in the URL field:<br>

      <figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FN3freoVDxQNWrXLEnFg9%2Fimage.png?alt=media&#x26;token=682b3eaa-673f-4e7a-8951-9a273c2203b2" alt=""><figcaption></figcaption></figure>

   3. Press `Test Komment Service` to ensure Komment and Kaptain service are connected<br>

      <figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FyHRKUUNzWfz7Dmi1VyoB%2Fimage.png?alt=media&#x26;token=32efa7f6-016a-4aca-a338-aa7bebd18b42" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Be aware of the protocol, and service port, that needs to be consistent with the settings in Kaptain config file.
{% endhint %}

### Kaptain Settings

To setup your Komment object to work with Kaptain there are only a few steps needed. You find the Kaptain Settings Under Data Connection Settings:<br>

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FctXYjmpMwjDCYNjiDTaY%2Fimage.png?alt=media&#x26;token=505a4fb0-9d14-4502-8a11-f55ae84e4b8c" alt=""><figcaption></figcaption></figure>

#### 1. Select or Create Kapsule

Here you define where in Kaptain's internal database you want to save the data entered by the users when using Komment. A **Kapsule** corresponds to a collection in the database. You can think of it as a table in a SQL database.

* If you have already created a Kapsule you can select from the list\
  ![](https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FlC5dtNWF8TwvNEiMj0lK%2Fimage.png?alt=media\&token=2b1c6a7b-8a91-4a65-8832-444041cd8dc2)
* If not, then
  * &#x20;Press `Create New Kapsule`&#x20;
  * You will now be presented with the following window:\ <br>

    <figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FnnBxZNrJ8QhciHArTmEz%2Fimage.png?alt=media&#x26;token=a289c6e6-d6d6-4188-8518-326f24522103" alt=""><figcaption></figcaption></figure>
  * If you want to store data in Kaptain's internal DB do the following:
    * Enter a Name for your new Kapsule
    * Choose KaptainDB as your database
    * Press `Create Kapsule`
  * If you want to store data in an external DB do this:

    * Enter a Name for your new Kapsule
    * Choose your desired DB from the list

    <figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FDGzYOJym6IgYDTOQMQsO%2Fimage.png?alt=media&#x26;token=a6c38e85-48b4-478d-b2c7-f3d0736a48c2" alt=""><figcaption></figcaption></figure>
  * If you want to use an existing table in the selected DB then choose your database table from the dropdown and press `OK`

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FXbdafZJ8yRU17YEwGeMv%2Fimage.png?alt=media&#x26;token=aa5cf20b-baa4-4ba9-a064-606d707524b6" alt=""><figcaption></figcaption></figure>

* If you want to create a new table in your selected DB then select `Create new table`
  * Enter the name of the new table and press Create Kapsule

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FCaJt9bvHLx92qCpphqhY%2Fimage.png?alt=media&#x26;token=0f511f12-252d-499b-92c2-6166e233a03b" alt=""><figcaption></figcaption></figure>

* &#x20;In the Kaptain Settings menu you can now see the newly created Kapsule selected in the list

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2F4dsKG2CD93myvgRqXA4e%2Fimage.png?alt=media&#x26;token=c29ff112-d902-4385-89f0-7e9c0d8501e4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you cannot find specific Kapsules in the dropdown menu, contact your admin to ensure you are setup as a Kaptain user and is member of the groups that contain the relevant Kapsules.
{% endhint %}

{% hint style="info" %}
If you are not able to create a new Kapsule, contact your admin to ensure you are setup as a Kaptain user and has the permissions the create kapsules.
{% endhint %}

**2. Use variable to select Kapsule dynamically**

To be able to easily moved applications with Komment between different Qlik servers and Kaptain installations you can define the Kapsule dynamically using a variable. Here is how.

* After you have selected your Kapsule as described above, you do the following:

  * Copy the Kapsule ID shown below the Kapsule you have selected

  <figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FdgRXtxaYOwE7GbVdNyQA%2Fimage.png?alt=media&#x26;token=0d2b1b79-0689-456a-b413-c69bcf86e2d9" alt=""><figcaption></figcaption></figure>
* Create a new variable using Qlik's variable editor (or define in script) and insert the copied value in the variable value

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FL1HE9BbPOGcsGaqsNVCZ%2Fimage.png?alt=media&#x26;token=6cfc2141-ec02-4b84-b1b3-08d2114b0b5f" alt=""><figcaption></figcaption></figure>

#### 3. Kaptain Data Connection

Here you can create a Qlik Sense Data Connection that will ensure you can load data from Kaptain. You just choose a name and a REST connection to Kaptain will automatically be established.

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2Fn2VYx37zfURnIkIUWFco%2Fimage.png?alt=media&#x26;token=c45ac480-9a7c-4fa7-832d-cc0751f15deb" alt=""><figcaption></figcaption></figure>

* If a REST data connection to Kaptain is already created you can select this
* If not, then
  * Press `Create Connection`
  * Write desired name of connection in pop-up window
  * Press `OK` (browser window will automatically refresh)
  * Select the newly created data connection from the list&#x20;

#### 4. Optional settings

`Load Full History:`&#x20;

Defines how much of the history data you load from Kaptain and into your Qlik Sense app on each reload (partial and full). By default only the latest record for each Komment Key field will be loaded so to get the full audit trail loaded each time toggle on this option.

`Skip Reload:`&#x20;

When this option is enabled, Kaptain will not perform a partial reload after the user press save. This means that the stored data will only be visible in the Komment table and not any native Qlik objects. The reason is that the saved data will not be included in the Qlik data model until a full reload of the app is performed.&#x20;

When to use the Skip Reload function? If you have large applications where partial reloads takes a long time. Or if you do not need to make use of the saved data in any Qlik visualizations in real time.

`Reload Notification:` When this option is enabled the user will see information about the partial reload status after pressing save.

When to show the Reload Notification function? If you have large applications where partial reloads takes a long time and you want to give the user an indication of the reload process.

{% hint style="warning" %}
Remember to initialize the data model again after you have finalised the Kaptain setup
{% endhint %}

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FaUrNVyo8IRBZGIkUdDgs%2Fimage.png?alt=media&#x26;token=b255e6cf-dbd5-4c3e-85f8-d1bed69c411b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FFBefqt3zWg09c0iRMs7F%2Fimage.png?alt=media&#x26;token=9cd36c83-c990-4743-b60a-512a2529f2b5" alt=""><figcaption><p>Initialize Data Model</p></figcaption></figure>

#### 4. Sync Kapsule

if you  add new widgets or remove existing widgets in your Komment setup you need to press `Sync Kapsule` to enforce the changes to be reflected in the Kapsule.

<figure><img src="https://4099892881-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXdGSelEVi2ug2LCBzJx5%2Fuploads%2FIbkARmbbp4F7jpUBonx9%2Fimage.png?alt=media&#x26;token=a854454f-ac6b-4520-8bbe-5753a469371f" alt=""><figcaption><p>Sync Kapsule</p></figcaption></figure>

**5. Known limitations**

`Field names:`

The field names used in the Komment widgets cannot contain the following characters: `. $`

`Kapsule names:`

Kapsule names should begin with an underscore or a letter character, and *cannot*:

* contain the `$`.
* be an empty string (e.g. `""`).
* contain the null character.
* begin with the `system.` prefix.

You can learn more here: <https://docs.mongodb.com/manual/reference/limits/>
