# Adding Basic Structure using Class Designer

The first step in building every application is to create a structure in the **Class Designer**.

{% hint style="info" %}
For in-depth documentation about data modelling, you can also check out the Data Modelling page.
{% endhint %}

{% content-ref url="../../building-an-application/data/data-modelling" %}
[data-modelling](https://docs.tivity.one/building-an-application/data/data-modelling)
{% endcontent-ref %}

## Creating a new Class

To add a new class, while still being in the **Config Mode** of your application, click on **Classes**, then in the next window click on **New Class**.

![Creating a new class ](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-M9xzyp1BBeYaeqwyjOX%2F-M9y6jVaZ__iSMc_a-BW%2FCreate%20Class.gif?alt=media\&token=17754f85-0c2e-498f-8b28-8c88ae33766b)

We can now configure our new class in the new window.

### Common Tab

Choose a unique name for both the **Key** and **Name** fields, for example, "MyToDo". Under **Class Type**, we also need to check the **Is Independent** and **Auto-Save** checkboxes. We will refer to this class as the To Do Class in this tuitorial.

When **Auto-Save** is checked, user changes are saved automatically.

{% hint style="info" %}
**Key** is the name we use to this specific class on the TIVITY platform.

**Name** is what is displayed to the user.
{% endhint %}

![MyToDos Class Common Tab](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAX85RiBngNkQiPAGkm%2FClass%20Common.jpg?alt=media\&token=807e5a28-418d-49cf-8d2b-69afcb4dce2d)

### Mapping Tab

The **Key** in the **Mapping Tab** represents the name of the table in the database.

![MyToDos Class Mapping Tab](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8HTRblOKav_qm4KEx6-887967055%2Fuploads%2FL6cplgHJ6h51KrUg1pw2%2Fimage.png?alt=media\&token=65218a85-9d90-4c43-99f9-e2d7b4b9c865)

{% hint style="warning" %}
It is important that the key with the table name does **not** already exist in the database. Otherwise you will get errors. See chapter: Write structure.
{% endhint %}

For this tutorial, no changes are required in the **Advanced Tab** or the **Permissions Tab**, so we can move on directly to the **Fields & Actions Tab**.

### **Fields & Action Tab**

As its name suggests, this tab allows us to create new fields and actions. Some fields and actions are already present by default.

![](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-M9y7RpEZPcwlPpVxRzn%2F-M9yEbS55eok9ZRECcol%2FFields%20%26%20Actions.png?alt=media\&token=272188c7-ca9c-4c2c-b650-0c53496cb5f4)

## Adding New Fields to a Class

To start adding a field to our class, type your field name in the **Add new field** text box and press **Enter**.

![Adding New Fields to a Class](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MA0b7BRDjDaCAUMjpgC%2F-MA139w5sLcFSah9Inqw%2FClass%20Add%20New%20Field.gif?alt=media\&token=3df228ce-dfbc-4f99-811c-8b9bf2eea0c0)

### **Common Tab**

Each field has a **Key**, an **Internal Key,** and a **Name**. They also have a **Data Type** to describe what kind of data is present in the field and a **Control Type** to define what kind of **Control** to use for data input.

### Mapping Tab

Settings on this tab are used to configure the mapping from our field to the database. Once again we need to define a **Key**.&#x20;

**Data Type** and **Length** describe the type of data and its size respectively when stored inside the database.                    &#x20;

{% hint style="info" %}
Assigning a value of **-1** to **Length** instructs the database to use the maximum length for the data type specified.
{% endhint %}

Finally, the **Is identity** checkbox indicates whether the database should auto increment the value of the field, and **Is nullable** indicates if this field can be null.

We will be adding the following fields to our class :&#x20;

* [Title](#title)&#x20;
* [Note](#notes)
* [Priority](#priority)
* [CreatedOn](#createdon)
* [DueDate](#duedate)
* [IsCompleted](#iscompleted)
* [ModifiedOn](#modifiedon)
* [CreatedBy](#createdby)
* [Owner](#owner)
* [ModifiedBy](#modifiedby)

### Title

The first field we are going to add to our class is the "Title" field which will store the title of the task.

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `Title`
* [ ] Set **Data Type** to `String`&#x20;
* [ ] Set **Control Type** to `TextBox`

In the **Mapping Tab**

* [ ] Set the **Key** to `Title`
* [ ] Set **Data Type** to `nvarchar`
* [ ] Set **Length** to `-1`

![Title Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXAUsXwa1G8rbP3zqx%2FField-Title.jpg?alt=media\&token=481539df-86be-4daa-8f7e-ada7cba062a3)

### Notes

The "Notes" field will store notes that we can attach to our tasks.&#x20;

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `Notes`
* [ ] Set **Data Type** to `String`&#x20;
* [ ] Set **Control Type** to `TextArea`

In the **Mapping Tab**

* [ ] Set the **Key** to `Notes`
* [ ] Set **Data Type** to `nvarchar`
* [ ] Set **Length** to `-1`

![Notes Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXBNnHSY0o8oFoatJO%2FField-Notes.jpg?alt=media\&token=7b1fa768-fd02-48f7-a341-7476921d6054)

### Priority

In the "Priority" field, we will store the priority of the task. This time we want our field to have only 3 possible options: "Normal", "Medium" and "High". To achieve this, we will set the **Data Source Type** as **Options** and list our possible values.

We also want to use a slider to set the priority of the task, so we set the **Control Type** to **Slider**.

![Priority Slider, with predefined options](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MA269Lgqr5WzzcRhMDe%2F-MA2KAimxHTJNbqANr8L%2Fslider.png?alt=media\&token=cb339c3a-1b1c-44c4-8595-0eb3a7404bf6)

We also want our task item to have a default priority "Normal" when created, so in the **Advanced Tab**, we set the **Default Mode** to "Creation" and the Default Expression to "Normal"

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `Priority`
* [ ] Set **Data Type** to `String`
* [ ] Set **Control Type** to `Slider`
* [ ] Set **Data Source Type** to `Option`
* [ ] Add the following **Options**, one option per line `Normal`, `Medium` and `High`

In the **Mapping Tab**

* [ ] Set the **Key** to `Priority`
* [ ] Set **Data Type** to `varchar`
* [ ] Set **Length** to `10`

In the **Advanced Tab**

* [ ] Set the **Default Mode** to `Creation`
* [ ] Set **Default Expression** to `Normal`

![Priority Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXDErf7yrMZ-k9q3_B%2FField-Priority.jpg?alt=media\&token=c2f55b6c-ddc2-4aee-8494-7b436cbae690)

### CreatedOn

The **CreatedOn** is a special field which the platform automatically detects it and is automatically set to the corresponding date and time when an object is created.

{% hint style="warning" %}
Make sure to spell "CreatedOn" correctly for this feature to work!
{% endhint %}

We also do not want anyone to modify this field, so we check the **Is Read Only** checkbox in the **Advanced Tab**.

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `CreatedOn`
* [ ] Set **Control Type** to `Calendar`
* [ ] Set **Data Type** to `DateTime`

In the **Mapping Tab**

* [ ] Set the **Key** to `CreatedOn`
* [ ] Set **Data Type** to `datetime`
* [ ] Set **Length** to `-1`

In the **Advanced Tab**

* [ ] Check the **Is Read Only** box

![CreatedOn Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXEx3NnGWByDVUFNK0%2FField-CreatedOn.jpg?alt=media\&token=8a40a462-226f-4b7f-bd68-ba08b4b6cf50)

### DueDate

The "DueDate" field will allow the user to input a due date for the task using the Calendar control.

<img src="https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MA2Qy2G0nLE5NAxnvma%2F-MA2SUCCxR85bFsgfE24%2FCaledar%20Control.png?alt=media&#x26;token=c7c1f823-8d0a-403e-9a58-c1daf5881be4" alt="" data-size="original">&#x20;

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `DueDate`
* [ ] Set **Data Type** to `DateTime`
* [ ] Set **Control Type** to `Calendar`

In the **Mapping Tab**

* [ ] Set the **Key** to `DueDate`
* [ ] Set **Data Type** to `datetime`
* [ ] Set **Length** to `-1`

![DueDate Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXGQhbymBc_AL_ga2a%2FField-DueDate.jpg?alt=media\&token=3c8d494a-7653-42ba-b80c-d876cdec01f7)

### **IsCompleted**

The is completed field will indicate whether the task is completed or not.

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `IsCompleted`
* [ ] Set **Data Type** to `Boolean`
* [ ] Set **Control Type** to `CheckBox`

In the **Mapping Tab**

* [ ] Set the **Key** to `IsCompleted`
* [ ] Set **Data Type** to `bit`
* [ ] Set **Length** to `-1`

In the **Real Field**

* [ ] Set the **Default Mode** to `Creation`
* [ ] Set **Default Expression** to `0`

![IsCompleted Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXHdGB13Yx316bjdI0%2FField-IsCompleted.jpg?alt=media\&token=23829547-47c3-4e53-ada7-6549207bc0cd)

### ModifiedOn

**ModifiedOn** is a special field that is automatically detected by the platform and is automatically set to the date and time when an object is modified.

&#x20;We also want that field to be read-only.

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `ModifiedOn`
* [ ] Set **Data Type** to `DateTime`

In the **Mapping Tab**

* [ ] Set the **Key** to `ModifiedOn`
* [ ] Set **Data Type** to `datetime`
* [ ] Set **Length** to "-1"

In the **Advanced Tab**

* [ ] Check the **Is Read Only** box

![ModifiedOn](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAX4R4jc_UG5_v6wbmH%2F-MAXIkVbQ7Sj8z-WQuZ9%2FField-ModifiedOn-horz.jpg?alt=media\&token=3beed4f7-51d2-42c4-867b-58e6b33de692)

### CreatedBy

CreatedBy is a special field that is automatically detected by the platform and is automatically set to the unique identifier of the current user when an object is created.

This field is set to read-only.

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `CreatedBy`
* [ ] Set **Data Type** to `Guid`

In the **Option Source** :

* [ ] Set **Data Source** Type to `Controller`
* [ ] Set **Data Source Controller** to `OfficeUserIdSourceController`

In the **Mapping Tab**

* [ ] Set the **Key** to `CreatedBy`
* [ ] Set **Data Type** to `uniqueidentifier`
* [ ] Set **Length** to `-1`

In the **Advanced Tab**

* [ ] Check the **Is Read Only** box

![CreatedBy Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAXUt_x7iLjG_9FGQIG%2F-MAXV9ZS9qeka1anN_Z2%2FField-Created-By.jpg?alt=media\&token=e47ec295-c721-4a56-97ef-1689975eee9b)

### Owner

For this tab we want the user to be able to assign ownership of the task by picking any user in the workspace. The TIVITY platform has a predefined implementation for this kind of operation called a **Controller.**

For this field, we use the "Combo Box" **Control Type,** and to populate it with users of the workspace, we set the **Data Source Type** as Controller and the **Data Source Controller** as **OfficeUserIdSourceController**

When created, we also want the default owner to be the current user if no one user been specified.  To achieve we, we go head to the Advanced Tab and set the **Default Mode** to **Creation** and the **Default Expression** to `{CurrentUser.Id}`

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `CreatedBy`
* [ ] Set **Data Type** to `Guid`

In the **Mapping Tab**

* [ ] Set the **Key** to `CreateBy`
* [ ] Set **Data Type** to `uniqueidentifier`
* [ ] Set **Length** to `-1`

In the **Advanced Tab**

* [ ] Set the **Default Mode** to **Creation**
* [ ] Set **Default Expression** to `{CurrentUser.Id}`

![Owner Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MAXUt_x7iLjG_9FGQIG%2F-MAXWROwAwsQHt55rmhy%2FField-Owner.jpg?alt=media\&token=cb15f179-21f8-4967-95dd-953973c0493c)

### ModifiedBy

ModifiedBy is a special field that is automatically detected by the platform and is automatically set to the unique identifier of the current user when an object is modified.

This field is set to read-only.

In the **Common Tab** :

* [ ] Set **Key**, **Internal Key,** and **Name** to `ModifiedBy`
* [ ] Set **Data Type** to `Guid`

In the **Mapping Tab**

* [ ] Set the **Key** to `ModifiedBy`
* [ ] Set **Data Type** to `uniqueidentifier`
* [ ] Set **Length** to `-1`

In the **Advanced Tab**

* [ ] Check the **Is Read Only** box

![ModifiedBy Field Properties](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MA2VXTDVb40y1mGNOoj%2F-MA2bNZyFRGFguOiu6gB%2FField-ModifiedBy.jpg?alt=media\&token=8ade5296-1f6c-42f8-bc44-2045e2daa39a)

### Save class

Now having created all the fields, we can save our class by clicking on the **Save** button.&#x20;

![Saving the class](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MA6BCsSD89fk4x15bMO%2F-MA6Hdl1AszU7R701fhm%2Fsave-class.gif?alt=media\&token=dfa2df77-9200-4d7b-920e-2554a538d413)

{% hint style="info" %}
TIVITY will validate all fields and give out warnings if any errors are present in the class.
{% endhint %}

### Write structure

Now a physical structure of the newly created and configured class must be created. For example, in the case of an SQL database, a table is created in the database as a data source in which the instances of this class can later be stored.

The action to create the structure is located in the upper right corner of the designer. Open the menu there and select the action *Write Structure*.

![Class designer](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MRey5vUswLDty07xlZS%2F-MRf-WvCHs9hjcSiq2cs%2FClassDesigner-WriteStructure.png?alt=media\&token=a03ae9e7-f437-4a8d-9d64-74f3f0367b48)

The action *Read Structure* executes the reverse way. The structure is transferred from the data source and the classes are updated or created in the Designer. For example, in SQL database as data source changes of a table (new column added) is transferred to the class model.

{% hint style="info" %}
If a newly created class already exists or fields are duplicated, a validation error occurs.
{% endhint %}

![Structure validation error](https://2608258621-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HTRblOKav_qm4KEx6%2F-MR_mzhFKdXPvERbxWR2%2F-MRa1qXpX4Kwzpn7SCNS%2FClassDesigner-StructureError.PNG?alt=media\&token=3fc2838e-922d-429b-8f8a-3b857025ffc2)
