# User-Defined Function

This guide explains how to map and utilize custom or system functions within the TrustLogix platform to build dynamic data access policies.

**Important Note:** TrustLogix does not create functions directly in your target data source. It simply maps existing data source functions within the TrustLogix UI so they can be referenced and applied during policy creation.

#### Pre-requisites

Before mapping a function in TrustLogix, ensure the following:

* **Required Permissions:** Grant **USAGE** permissions on the database, schema, and the specific function to the `tlx_dp_role`.
* **Function Availability:** Ensure the function is already mapped in the TrustLogix UI as a **Custom Function**.

#### Mapping the Function

To make a function available for policies, you must first register it in the TrustLogix dashboard:

1. **Navigate**: Go to Configurations -> User Defined Function.
2. **Tab Selection**: Select the Custom Functions tab.
3. **Initiate Mapping**: Click the + Custom Function button.
4. **Selection Steps**:
   1. Select the Database from the dropdown menu.
   2. Select the Schema belonging to that database.
   3. Select the specific Function you want to map.
5. Error Handling (Validation): **Duplicate Check**: TrustLogix will validate if the function has already been mapped. If you attempt to add a function that already exists in the system, an error message will appear preventing the duplicate entry.

#### Applying Functions in Policy Conditions

Once the function is registered, it can be used in your Row Access Policies (RAP) or Masking Policies.

**Steps to Implement:**

1. Navigate to your **Data Source** and select **Access Policy**.
2. Choose to **create a new policy** or **edit an existing** RAP or Masking Policy.
3. In the **Condition Builder**, locate the **System or Custom Function** option.
4. Select your mapped function from the list to define your policy logic.

#### **Limitations**

While the Condition Builder is flexible, the following limitation applies:

* **Nesting Support:** The Condition Builder supports function nesting up to **one level only**.
  * ✅ Supported: `FunctionA(FunctionB(column))`
  * ❌ Not Supported: `FunctionA(FunctionB(FunctionC(column)))`
* **Complex Expressions:** For multi-level nesting, use the *Custom Expression* field starting from the second level onward.
  * Example: `FunctionA(FunctionB(FunctionC(column)))`


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.trustlogix.io/configurations/user-defined-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
