# Types

### Simple Types

The[ Linx plugin](https://docs.linx.software/reference/plugins/linx) contains all Simple Types. These include:

* [Boolean](https://docs.linx.software/reference/plugins/linx/content/boolean)
* [Byte](https://docs.linx.software/reference/plugins/linx/content/byte)
* [DateTime](https://docs.linx.software/reference/plugins/linx/content/datetime)
* [Decimal](https://docs.linx.software/reference/plugins/linx/content/decimal)
* [Double](https://docs.linx.software/reference/plugins/linx/content/double)
* [Integer](https://docs.linx.software/reference/plugins/linx/content/integer)
* [String](https://docs.linx.software/reference/plugins/linx/content/string)

Use a Simple Type to create a variable in a Function by:

1. Dragging the type from the plugins panel onto the body of a Function.
2. Setting the *Value* property.

![Using Simple Types](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-cdbfbe407c91fb2b47807c05dfbbfddf9e9c6f2d%2Ftypes1.png?alt=media)

***

### Complex Types

In the Linx Designer, Complex Types are just referred to as *Types*.

A *Type* in Linx works just like a JSON object. *Types* contain collections of named properties. Each property represents a *Simple Type*, a complex *Type*, or a *List*.

**Creating a Complex Type**

1. Click the *Type* button in the toolbar to add a type to your solution.
2. Set a name for the *Type* in the Properties panel.
3. Add properties to the *Type* using the *Type Editor*:
   * Add a name for each property in the *Name* column.
   * Select the property type in the *Type* column dropdown.

![Using Complex Types](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-5d1bdabe7104cfbb540a82519b1e0f80dbc825f2%2Ftypes2.png?alt=media)

This example shows a \*Type\* with four properties (Address is of type 'Type\_Address', Children is a List of type 'Type\_Child', DOB is of type DateTime, and Name is of type String)

Here is a JSON representation of the Type\_Person type:

{% code overflow="wrap" %}

```json
{ "Person": { "Address": { "Street": "", "City": "", "POCode": "" }, "Children": [], "DOB": "", "Name": "" } }
```

{% endcode %}

## Using a Complex Type

1. Drag the Type from the Solution Explorer onto the Function body.
2. By default, the type is instantiated as empty using squiggly brackets `{}`, but its properties are not initialized and default to null.

![Instantiated, empty type](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-de4564f4b6ec030810d4d5448ced2ea64cac0e5e%2Finstantiated.png?alt=media)

3. Set values for Type properties by either:
   * Launching the Values Editor to add values.

![Drag the type into the Function](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-b0e9c2d8c73f4537a57c8bb446b81b3cb3ecda83%2Ftypes3.png?alt=media)

```
*   Using a[ SetValue](../reference/plugins/linx/content/setvalue.md) function.
```

<div align="left"><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-b2e8de75b3507edd5bef8a0e8cb05161b075f3a2%2Fset-name.png?alt=media" alt="Using a SetValue to set a Type property"></div>

***

### Lists

Lists can be of any simple or complex type.

#### Creating a List

1. Drag a [List](https://docs.linx.software/reference/plugins/linx/content/genericlist) from the Linx plugin onto the Function body.
2. An empty List will be initialized using square brackets `[]`.
3. Choose the List type in the property dropdown (it defaults to String).

![Select a List type](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-65b8904c6623ae3f8929f8f69448aad3760bd9ce%2Ftypes5.png?alt=media)

#### Adding Items to Lists

Add items to Lists by either:

1. Launching the List editor.

![Using a List](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-dbaf5abad0e25ad9bfb63a21d52cd8708eb3f5dd%2Ftypes4.png?alt=media)

1. Dragging an[ AddToList](https://docs.linx.software/reference/plugins/linx/content/addtolist) function into the Function.
2. Selecting the List and value to add in the AddToList properties.

![Adding to a List](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-6ad35f220cf3d45e3dd49ee53481404c706b7049%2Faddtolist.png?alt=media)

Other functions to manipulate the list are available in the Linx plugin.

![List Functions](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-94a34cf54bd4d5d98907234888d121faffd5d9ba%2Flistfunctions.png?alt=media)

***

### Assignment Errors

A common problem is caused by the attempt to assign values to NULL elements.

1. To set a value for a property of a complex type, the type cannot be null.

   ![Attempting to set an uninstantiated type causes an 'Object reference not set to an instance of an object' error](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-5d9e206f79367b3af4bc1b74f2a0005bbea73e97%2Fnull-types.gif?alt=media)
2. Instantiate a Complex type inside another one with `{"PropertyName":{}}`.

   <div align="left"><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-c2cad9c5e2c30a37f990b7a6000c8f511a8c9bb1%2Fcomplex-type-instantiate.png?alt=media" alt="Complex types that are properties of other complex types must be instantiated before they can be used"></div>
3. Lists must be instantiated before they can be added to.

   ![Attempting to add items to an uninstantiated List causes a 'Cannot add to list as it is null' error](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-85d81bfc55501a95df9d0715a94010ddd599f303%2Fnull-list.gif?alt=media)
4. Instantiate Lists that are properties of complex types with `{"PropertyName":[]}`.

   <div align="left"><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-447227c4abe755bfaba31e447001b013f6dc0caa%2Finstantiated_child_list.png?alt=media" alt="Lists that are properties of complex types must be instantiated before they can be used"></div>

***

### Tutorial Video

{% embed url="<https://youtu.be/LwHlp1UAwOk>" %}
