# LEN() Function

**YouTube:** [How to Use the Len Function in Report Custom Columns?](https://www.youtube.com/watch?v=6a_VwqzlEds)

## How to Use the Len Function in Report Custom Columns?

In this tutorial, we will learn how to create expressions using the **`LEN` function**, which calculates the number of characters (length) in a given field such as `Item Code`. You’ll apply this function both in the **grid view** and within a **report layout**.

***

### Accessing the Expression Designer:

* Open Sale Voucher or any document.
* Navigate to the "**Setup Column Attributes"**.
* Here, you'll see a list of available columns that can be used to build expressions.
* Click on **"Add/Edit Expression Columns"** where you can write your expression using predefined functions.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FBiD7B0nHi6iarn4CKfDv%2FBill%20Setup%20column%20attribute.png?alt=media&#x26;token=a582faef-5c69-4eb5-ac56-48057aaab80b" alt=""><figcaption></figcaption></figure>

### Writing Your First Expression

* Every expression must start with the script header: **'#@LSCRIPT**

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2F6sCEhRlGWfBL2O3Tg0XY%2FBill%20Setup%20column%20attribute%20Default%20Script.png?alt=media&#x26;token=af5f02ec-c5a6-41e5-bf23-16e2265b02e7" alt=""><figcaption></figcaption></figure>

* Click the (+) Plus icon to create a new expression.
* Fill in the required fields:&#x20;
  * **Expression Name** – A unique name for your expression.
  * **Expression Type** – Choose either **Text** or **Numeric** depending on the expected output.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FVaIlbYOLWZr6n9xpdYwg%2FSale%20Bill%20LEN%20function.png?alt=media&#x26;token=03cbd9f3-823f-4ee0-9796-e0c6e8500b9c" alt=""><figcaption></figcaption></figure>

***

### Define the LEN Function Expression

* Double-click the newly created expression to insert it into the script editor.
* Enter the function using the following syntax:
* Expression Name = LEN(ITEM\_CODE)

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FarnwYFiXTsOjMQeK1kpz%2FItem%20Code%20Formualk.png?alt=media&#x26;token=d1268afa-c066-45be-9c25-26def61a600b" alt=""><figcaption></figcaption></figure>

* Click **Save** to apply the expression.
* Scroll down and **check the box** next to your expression to display it in the data grid.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FKszSEQbvya0FrM8YRyxz%2FSKU_LEN%20Formula.png?alt=media&#x26;token=5275268d-f9c2-4c16-b585-5ec955e5e848" alt=""><figcaption></figcaption></figure>

* Save and proceed to check the effect.
* The grid will now display a new column showing the **length** of each Item Code.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FSVJobiSbJWoDDlBEbTT2%2FItem%20Code%20Count%20in%20sale%20bill.png?alt=media&#x26;token=761989e5-70a9-4cbe-8408-a286162c0103" alt=""><figcaption></figcaption></figure>

***

### Applying the Expression in a Report

* Navigate to the **Reporting** section.
* Open the **Sales Register Detailed Report** or any **"Report".**
* Go to **Setup Column Attributes** as you did earlier.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FzzrXSOCyLMEEqwUGMCtf%2FReport%20Setup%20Column%20attribute.png?alt=media&#x26;token=a4523cec-3f63-49a5-80ff-2d551144069f" alt=""><figcaption></figcaption></figure>

* Before adding the expression to the report, go to **Other Settings**.
* Ensure the **Script Editor** is set to **VBScript**.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FPgRPBYdOmbcuIH0PZ7sI%2FOther%20Setting%20-%20VB%20Print.png?alt=media&#x26;token=60981fe7-c38c-4bf4-a8d9-40a3289ddbd7" alt=""><figcaption></figcaption></figure>

* Click **Save**.
  * *Note: VBScript is the default for new configurations but always verify this setting.*

***

### Adding and Using the Expression in the Report

* Return to **"Setup Column Attribute"** window.
* Click **"Add/Edit Expression Columns"**.
* Every expression must start with the script header **'#@LSCRIPT**

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FAhoPOYUyaXB1naXYCylF%2FReport%20Default%20Script.png?alt=media&#x26;token=d82fd708-cc96-4e35-90e5-bc3905f7db4b" alt=""><figcaption></figcaption></figure>

* Click the (+) Plus icon to create a new expression.
* Fill in the required fields:&#x20;
  * **Expression Name** – A unique name for your expression.
  * **Expression Type** – Choose either **Text** or **Numeric** depending on the expected output.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FpFQDYiGMZvdHasbPyIPK%2FItem%20Code%20Formula%20in%20Report.png?alt=media&#x26;token=c4a1a315-60d5-4c8e-a754-354f8db49762" alt=""><figcaption></figcaption></figure>

* Double-click the expression to insert it into the script editor.
* Define the expression using:
  * Expression Name = LEN("ITEM\_CODE")
  * This function converts the item name to uppercase letters.
* Click **Save**.
* Scroll down and **check the box** to enable the expression column in the report.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2Fr1CPZkChlifJyUZ6HsKu%2FReport%20Setup%20Column%20Attribute.png?alt=media&#x26;token=7c249dcc-a0f7-4d42-b0b4-544468a82a17" alt=""><figcaption></figcaption></figure>

* Save and proceed to check the effect.
* **Refresh the report** to view the final result.
  * The report will now display a column showing the **length of each Item Code** as per the defined expression.

<figure><img src="https://4031188996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXMVkjt8zqHBQX1c9QvFS%2Fuploads%2FYK96euUxRrttYWYZ07oi%2FResult%20in%20Report.png?alt=media&#x26;token=3d621b1f-7bb6-41fa-bff7-da671a0f8514" alt=""><figcaption></figcaption></figure>

***


---

# 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://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/defining-custom-columns-in-reports-and-grids-with-expressions/len-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.
