# Custom Logic

### Introduction

A Custom Logic Block can be used to evaluate complex logic that can not be implemented with a simple comparison block.

A set of example logic blocks can be found here:

This webinar explains how to create **Custom Rules**:

{% embed url="<https://github.com/akenza-io/akenza-logic-block-examples>" %}

{% embed url="<https://www.youtube.com/watch?t=4s&v=weoSqm7Ugao>" %}
Webinar about how to create Custom Rules
{% endembed %}

### Overview

**Custom Logic Blocks** allow the implementation of more complex business logic with the akenza **Rule Engine**. They enable simple stateless and stateful operations upon rule trigger using custom scripts in **Javascript**. Custom Logic Blocks are created on organization-level and are therefore available in all workspaces and can be selected when creating a rule.&#x20;

A Custom Logic Block consists of a definition of:

* **Inputs**: the dynamic data that is evaluated during script execution (sensor data)
* **Parameters**: constant values like thresholds
* A **script** used to run the logic

{% hint style="info" %}
In order to keep its usage consistent, it is not possible to edit custom logic inputs and parameters if the Custom Logic Block is assigned to an **active** rule.
{% endhint %}

### Inputs

Inputs specify the **input data sources** for a Custom Logic Block and contain the dynamic data of a device. At least one input needs to be defined in order to create a Custom Logic Block.

| Field                     | Description                                                                 |
| ------------------------- | --------------------------------------------------------------------------- |
| Input display/ label name | The input name                                                              |
| Input description         | An optional description                                                     |
| Input variable name       | A variable name used to access the value inside the script                  |
| Default topic             | An optional default topic that is preselected when using the logic block    |
| Default data key          | An optional default data key that is preselected when using the logic block |

### Parameters

Parameters represent **static properties** that are available during script runtime.

| Field                        | Description                                                    |
| ---------------------------- | -------------------------------------------------------------- |
| Parameter display/label name | The parameter name                                             |
| Parameter variable name      | A variable name used to access the parameter inside the script |
| Parameter Type               | The data type of the parameter; Numerical, String, or Boolean  |
| Default value                | A default value for the parameter                              |

### Script

{% content-ref url="custom-logic/logic-block-scripting" %}
[logic-block-scripting](https://docs.akenza.io/akenza.io/get-started/rule-engine/logic-blocks/custom-logic/logic-block-scripting)
{% endcontent-ref %}
