---
title: "Add functions to a Dynamic Document"
slug: "add-functions-to-a-dynamic-document"
updated: 2025-02-16T08:30:56Z
published: 2025-02-16T08:30:56Z
canonical: "knowledge.lightico.com/add-functions-to-a-dynamic-document"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://knowledge.lightico.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add functions to a Dynamic Document

## Add functions

You can add arithmetic functions into a section. For example, you may want to include a function that calculates the price after a discount for a certain item.

In some cases, you can insert *aggregate functions* that calculate the sum total when there are multiple instances of the same function. For example, if you have a function called *item_price* that is used in more than one instance, you can insert an aggregate function that will calculate the total of all the *item_price* functions.

### Limitations to using functions

The type of functions you can add to a section depends on what type of section you are adding them to. Sections that are bound to a Form behave differently to unbound sections. Binding a section of a Dynamic Document to a Form is used when [building a visual cart](/v1/docs/create-a-visual-cart). The following table summarizes the type of functions you can add to a section and what those functions can include:

|  | **Bound Section** | **Unbound Section** |
| --- | --- | --- |
| **Function** | Function can include: - *Attributes*used in the Form that is bound to this section - *other functions* that are defined in the current section | Function can include: - *other functions* from anywhere in the document - *aggregate functions* from anywhere in the document |
| **Aggregate Function** | Not available | Aggregate function can include *other functions* from anywhere in the document. |

### Add a regular function

**To add a regular function to a Dynamic Document:**

1. In the toolbar of the relevant section, click the **Add Function** button. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/Snag_1aa024bd.png)
2. In the dialog box that opens, click **Create New**. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/create_new_function.PNG) The Create Function window appears.
3. Enter the name of your function, for example *item_price*.
4. In the function box, enter the function itself.

For example, you can write the following function to calculate the price after a discount, that includes 2 attributes.

```plaintext
@document.price - @document.discount
```
  - In bound sections, you can use the **add function** button or the **add attribute** button to include attributes and functions that are used in this section.

![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/function%20and%20attribute%20buttons(1).PNG)
  - In unbound sections, you can use the **add function**button or the **add aggregate function** button to include functions and aggregate functions from anywhere in the document.

![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/function%20and%20aggregate%20function.PNG)
5. Click **Save**to save the new function**.**
6. Click **Save**to save the new function **.**
7. To add the new function into the section, click the **Add Function** button again and select the function you just created. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/select_function.PNG)
8. To edit or delete the function, click the relevant buttons next to the selected function.

### Add an aggregate function

1. Click the **Add Aggregate Function** button. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/Snag_1fb444b5.png)
2. In the dialog box that opens, click **Create New**. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/create_new_function.PNG)
3. In the Create Aggregate Function dialog box, in the title box, enter the name of your aggregate function.
4. In the function box, enter the function itself. You can use the **add function** button to insert a function from anywhere in the document. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/aggregated_function_dialog(1).PNG)

For example, you can write the following aggregate function to calculate the total of all the *item_price* functions:

```plaintext
item_price + 0
```
5. Click **Save**.
6. To add the new aggregate function into the section, click the **Add Aggregate Function** button again and select the function you just created. ![](https://cdn.document360.io/473bb8c5-ff1b-4930-8109-2321ac6ab967/Images/Documentation/select_agg_function.PNG)
7. To edit or delete the aggregate function, click the relevant buttons next to the selected aggregate function.
