---
title: "Send Email on Batch Operations Actions"
slug: "send-email-on-batch-operations-actions"
updated: 2025-02-06T17:26:38Z
published: 2025-02-06T17:26:38Z
canonical: "documentation.encodify.com/send-email-on-batch-operations-actions"
---

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

# Send Email on Batch Operations Actions

Batch Actions are triggered on the [operations with multiple items](/v1/docs/bulk-operations-with-items) and provide the ability to Send Email with aggregated data from the processed items.

The events handled:

| Event | Explanation |
| --- | --- |
| Batch File Upload | Creating items on Bulk Upload operation |
| Batch Combinations | Creating items by Execute Task Action "Create/Update items in another module" with combination option enabled |
| Batch Field Import | Creating/Updating multiple items via the Import mechanism |
| Batch Workflow | Updating items' status via Bulk Status Change operation |

![SendEmailBulk.png](https://cdn.document360.io/3a63e0a8-1221-4570-aaa1-d43f9b95a612/Images/Documentation/sendemailbulk.png)

The items' data can be fetched and formatted using the syntax of [Apache Velocity Engine](https://velocity.apache.org/engine/1.7/user-guide.html). Also, standard placeholders can be used for inserting the general data.

### Placeholders

---

Use standard placeholders to insert the data.

- `${BatchId}` inserts the identifier of the processed items batch.
- `${BatchType}` inserts the type of the batch: Upload, Combination, Import, Workflow.
- `${TotalItems}` inserts the total number of processed items.
- `${UserName}` inserts the name of the current user.
- `${UserEmail}` inserts the email address of the current user.
- `${SiteUrl}` inserts the URL of the current site specified in Site Settings, e.g. https://qatest.com.
- `${LoginUrl}` inserts the Login Page URL, e.g. https://qatest.com/qa/common/login/ebms.
- `${SiteId}` inserts the ID of the current site.
- `${ModuleId}` inserts the ID of the current module.

### Functions

---

Functions of Apache Velocity Engine allow to fetch and process the data from items.

The keyword `#set` is used for defining a variable. The system variable `$tools` is normally used for fetching data and calling functions. `$date` is a system variable for working with dates. Functions also can be called for the user-defined variables.

#### Basic Functions

| Syntax | Explanation | Returns |
| --- | --- | --- |
| ```plaintext #set($variableName = 'sometext') ``` | Define a variable that can be reused in the formulas. The variable can contain static text or result of the function | - |
| ```plaintext $tools.base64Encode('some string') ``` | Encode the string to Base64 format | String |
| ```plaintext $date.get('yyyy-M-d H:m:s') ``` | Inserts the action execution date by specified mask, e.g. 2018-3-19 21:54:51. More about [Formatting dates](https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/DateTool.html) | String |

#### Bulk Functions

| Syntax | Explanation | Returns |
| --- | --- | --- |
| ```plaintext $tools.fetchAll() ``` | Get a list of all item objects in a batch. Note, this function returns the objects array, not the text data. To process them use `foreach` syntax explained below | Array of Objects |
| ```plaintext $tools.fetchFirst() ``` | Get the first item object in a batch | Object |
| ```plaintext $tools.fetchUnique('field name') $tools.fetchUnique('field name', 'subfield name') ``` | Get all unique values in a batch of items by a specific field. If 'field name' is a module link, use additional 'subfield name' parameter to define a field in linked module | Array of Strings |
| ```plaintext $variable_with_item.fieldValue('field name') ``` | Get a single value from the item field | String |
| ```plaintext $variable_with_item.fieldValue('module link').fieldValue('subfield') $variable_with_item.fieldValue('user field').fieldValue('name') ``` | Get a value from the module link sub-field. This also works for User field (supported values: 'name', 'login', 'email', 'mobile_email', 'mobile') | String |
| ```plaintext $variable_with_item.fieldValues('multiselect field name') ``` | Get multiple values from the multiselect item field | Array of Strings |
| ```plaintext $tools.join(, 'delimiter', true/false) ``` | Format multiple values with a delimiter, e.g. as a comma-separated list. Set **true** to skip the items with empty values. is an array of strings | String |
| ```plaintext #foreach($currentItem in ) $currentItem. #end ``` | Iterate through the list of items and process them one by one in cycle. **Please, note!** "CurrentItem" (capital C) is working only for single operation actions. For batch operations, use **$currentItem**(lowercase c) as in provided help text in action configuration. | - |

#### Special Functions

| Syntax | Explanation | Returns |
| --- | --- | --- |
| ```plaintext $tools.report(templateId, 'filterValue', 'customName') ``` | Generate a link to download the report with processed items. - **templateId** — ID of the item with a template in Report module. - **filterValue** — a value to filter the report data. The filtering field has to be preconfigured in the report template. - **customName** — the name of the report file. See about [Reporting Tool](/v1/docs/create-and-configure-reports). | String |
| ```plaintext $tools.base64Encode('some string') ``` | Encode the string to Base64 format | String |
| ```plaintext $tools.aesGenerateKey('password', 'salt', , , 'algorithm') ``` | Generate a key using the AES key generator. The key can be used for encrypting/decrypting the data that must be secure (e.g. access token). See the [usage example](/v1/docs/ui-event-actions#redirect-to-custom-url) | String |
| ```plaintext $tools.aesEncrypt('value', 'key','init vector', 'cipher name') ``` | Encrypt value using the key and init vector. Cipher name is optional | String |
| ```plaintext $tools.aesDecrypt('enctypted value', 'key', 'init vector', 'cipher name') ``` | Decrypt value using the key and init vector. Cipher name is optional | String |

> [!NOTE]
> For more formulas see [Apache Velocity Engine](http://velocity.apache.org/engine/1.7/user-guide.html) documentation.

> [!WARNING]
> Single quote in field names must be escaped by an extra single quote:
> 
> ```plaintext
> $CurrentItem.fieldValue('Name with ''single  quote'' inside')
> ```
> 
> See more about [How to escape the special characters](https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/EscapeTool.html).

### Examples

---

- Generate a link to batch item list in Spreadsheet View using the predefined variable and standard bulk operation placeholders. Note, the path is encoded to Base64 format:

```plaintext
#set($targetPathGrid = "/site/${SiteId}/home#/module/${ModuleId}/view/list?batchId=${BatchId}")
${LoginUrl}?targetPath=$tools.base64Encode($targetPathGrid)
```

- Generate a link to batch item list in Gallery View:

```plaintext
#set($targetPathGallery = "/site/${SiteId}/home#/module/${ModuleId}/view/gallery?batchId=${BatchId}")
${LoginUrl}?targetPath=$tools.base64Encode($targetPathGallery)
```

- Generate a link to report file. The report will contain only the items from a specific campaign:

```plaintext
#set($customFilter = "$tools.fetchFirst().fieldValue('Campaign')")
#set($customName = "Report_$date.get('yyyy-M-d H:m:s')")
${SiteUrl}/$tools.report(26, $customFilter, $customName)
```

> [!WARNING]
> To be able to specify a filter set the key placeholder `{filterValue}` as a filtering value in the Report Template filtering settings:
> 
> | Field | Filter | Value |
> | --- | --- | --- |
> | Campaign | Contains | {filterValue} |
> 
> See more about [Reporting Tool](/v1/docs/create-and-configure-reports).

- Get the comma-separated list of unique emails from the items in a batch:

```plaintext
#set($emails = $tools.fetchUnique('User Link field', 'Email')) 
$tools.join($emails, ',', true)
```

- Iterate through the batch items and get a value of 'Created By' field for each item:

```plaintext
#foreach($currentItem in $tools.fetchAll())
    $currentItem.fieldValue('Created By')
#end
```

- Get the email for user field of the first item in a batch. Supported values: 'name', 'login', 'email', 'mobile_email', 'mobile':

```plaintext
$tools.fetchFirst().fieldValue('user field').fieldValue('email')
```

- Get the value from the specified field in the linked module:

```plaintext
$tools.fetchFirst().fieldValue('module link field').fieldValue('field in linked module')
```

- Get the pair 'Name - Email' for each user in multiselect User link field for every item in a batch. Note, the nested `foreach` cycles are used for that:

```plaintext
#set($allItems = $tools.fetchAll())
#foreach($currentItem in $allItems)
    #set($valuesInMultiUserField = $currentItem.fieldValues('MultiUserField'))
    #foreach($value in $valuesInMultiUserField)
        $value.fieldValue('Name') - $value.fieldValue('Email')
    #end
#end
```
