> For the complete documentation index, see [llms.txt](https://docs.akenza.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akenza.io/device-management/rule-engine/logic-blocks/custom-logic.md).

# Custom Logic

Evaluate rule logic with a JavaScript script.

A **Custom Logic** block runs a JavaScript script each time a rule is triggered. Use it for logic that a [comparison](/device-management/rule-engine/logic-blocks/rule-logic.md) cannot express. Scripts can be stateless, or keep a [state](/reference/scripting/stateful-operations.md) between runs.

Custom logic blocks are created at organization level. They are available in all workspaces and can be selected when you create a rule.

A custom logic block consists of:

<table><thead><tr><th width="160">Part</th><th>What it is</th></tr></thead><tbody><tr><td><a href="#inputs"><strong>Inputs</strong></a></td><td>The device data the script evaluates, such as a sensor value.</td></tr><tr><td><a href="#parameters"><strong>Parameters</strong></a></td><td>Constant values, such as thresholds, set when the block is used in a rule.</td></tr><tr><td><a href="/device-management/rule-engine/logic-blocks/custom-logic/logic-block-scripting.md"><strong>Script</strong></a></td><td>The logic that runs and emits actions.</td></tr></tbody></table>

{% hint style="info" %}
Inputs and parameters cannot be edited while the block is used in an **active** rule.
{% endhint %}

## Inputs

Inputs define the data sources of the block. They hold the dynamic data of a device. A block needs at least one input.

<table><thead><tr><th width="230">Field</th><th>Description</th></tr></thead><tbody><tr><td><strong>Display name</strong></td><td>The name of the input.</td></tr><tr><td><strong>Description</strong></td><td>An optional description.</td></tr><tr><td><strong>Variable name</strong></td><td>The name used to access the value in the script, as <code>event.inputs.&#x3C;name></code>.</td></tr><tr><td><strong>Default topic</strong></td><td>An optional topic that is preselected when the block is used.</td></tr><tr><td><strong>Default data key</strong></td><td>An optional data key that is preselected when the block is used.</td></tr></tbody></table>

## Parameters

Parameters are static values available while the script runs.

<table><thead><tr><th width="230">Field</th><th>Description</th></tr></thead><tbody><tr><td><strong>Display name</strong></td><td>The name of the parameter.</td></tr><tr><td><strong>Variable name</strong></td><td>The name used to access the value in the script, as <code>event.properties.&#x3C;name></code>.</td></tr><tr><td><strong>Type</strong></td><td>Numerical, String, or Boolean.</td></tr><tr><td><strong>Default value</strong></td><td>The value used unless the rule sets another one.</td></tr></tbody></table>

## Script

{% content-ref url="/pages/DGfTlO2tnmhTAEX595bu" %}
[Logic Block Scripting](/device-management/rule-engine/logic-blocks/custom-logic/logic-block-scripting.md)
{% endcontent-ref %}

## Examples

The example repository contains ready-made logic blocks:

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

This webinar shows how to create a custom rule:

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.akenza.io/device-management/rule-engine/logic-blocks/custom-logic.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
