---
title: "Velocity Syntax: Variables and Functions"
slug: "velocity-syntax"
updated: 2025-12-08T13:51:45Z
published: 2025-12-08T13:51:45Z
---

> ## 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.

# Velocity Syntax: Variables and Functions

This article presents an extensive compilation of the variables and functions that can be utilised when incorporating velocity code to set up [Actions](/v1/docs/actions), [Automation Rules](/v1/docs/automation-rules-1), or any other entities that permit its application. Both **variables** and **functions** are employed to embed dynamic content into a template, yet they have distinct primary functions and are organised in different ways.

## Variables

Variables are used as **placeholders to insert data**(objects, strings, numbers, booleans) to display or hold a specific piece of information.

| **Variables** |
| --- |
| **Use Placeholder** | **To Insert** |
| ${UserName} | *Name of the user* |
| ${UserEmail} | *Email address of the user* |
| ${SiteUrl} | *Value of "Site URL"* |
| ${LoginUrl} | *Value of "Login Url"* |
| ${SiteId} | *Current site ID* |
| ${ModuleId} | *Current module ID* |
| ${ModuleName} | *Current module name* |
| ${ActionId} | *Action ID* |
| ${CurrentItem} | *Current item* |
| ${comment} | *Comment content* |
| ${reply} | *Reply content* |
| ${reaction} | *Reaction to Comment* |
| ${commentStatus} | *Comment status with supported values: "resolved", "unresolved"* |
| ${previewText} | *Preview text* |
| ${StatusFrom} | *Status from* |
| ${StatusTo} | *Status to* |
| ${StatusComment} | *Comment specified for the status change* |
| ${BatchId} | *Batch ID* |
| ${BatchType} | *Batch type* |
| ${TotalItems} | *Total processed items* |
| ${ActionName} | *Name of the action that triggered the alert email* |
| ${RequestBody} | *Body of the HTTP request that triggered the alert email* |
| ${ResponseBody} | *Body of the HTTP response that triggered the alert email* |
| ${GuestUserLoginUrl} | *The URL by which a guest user can log in* |
| ${GuestUserEmail} | *The email of the guest user that the resource was shared with (Not recommended, use ${ShareReceiverEmail} instead)* |
| ${ShareReceiver} | *The name of the user that the resource was shared with, if they exist internally, else it inserts the email* |
| ${ShareReceiverName} | *The name of the user that the resource was shared with* |
| ${ShareReceiverEmail} | *The email of the user the resource was shared* |
| ${SharedEntityComment} | *The comment that was attached to the shared resource* |

## Functions

Functions are used to **perform an action** or **calculate/retrieve** a value based on an object's state.

| **Functions** |
| --- |
| **Syntax** | **Explanation** |
| #set($variableName = 'sometext') | *Define a variable that can be reused in the formulas* |
| $tools.join( <list of values>, '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. To get <list of values> use $tools.fetchUnique('field name')* |
| #foreach($<Variable With Item> in <list of items>) $<Variable With Item>.<operation> #end | *Iterate through the items’ list and process each item* |
| $<Variable With Item>.getId() $<Variable With Item>.id | *Get ID of item, for example $CurrentItem.getId()* |
| $<Variable With Item>.fieldValue(<Field Id>) $<Variable With Item>.fieldValue('<Field Name>') | *Get a single value from the item field* |
| $<Variable With Item>.fieldValues(<Field Id>) $<Variable With Item>.fieldValues('<Field Name>') | *Get multiple values from the item field. In case of a single or multiple file field returns File Option Value* |
| $<Variable With Value from Field>.getId() $<Variable With Value from Field>.id | *Get option id for any optional field, for example $CurrentItem.fieldValue('Client').getId()}* |
| $<Variable With Value from Field>.getValue() $<Variable With Value from Field>.value | *Get option value in unformatted raw value for any field, can be useful for number/date and sorting, formatting, etc. , for example $CurrentItem.fieldValues(15).value* |
| $<Variable With Value from Field>.getStringValue() $<Variable With Value from Field>.stringValue | *Get option string value for any field, for example $CurrentItem.fieldValue(25).stringValue* |
| $<Variable With Item>.changes() | *Get a list of changed fields containing field ID, field name, old value, and new value.* *In iteration on changes following data can be retrieved:* *.fieldId() returns the field ID of the changed item.* *.fieldName() returns the field name of the changed item.* *.newValue() returns the new value of the changed item.* *.oldValue() returns the old value of the changed item.* |
| $<Variable With Item>.changes().oldValue(' <field name>') | *Get the old value of the changed field, if it did not change, the result would be empty.* |
| $<Variable With Item>.changes().newValue(' <field name>') | *Get the new value of the changed field* |
| $<Variable With Item>.findFirstFileInMediaHolder(<Media Holder Id>) | *Get File Option Value* |
| $<Variable With Item>.findFilesInMediaHolder(<Media Holder Id>) | *Get File Option Values* |
| $<File Option Value>.toSignUrlLink() | *Generate a signed URL for the file* |
| $<File Option Value>.toUrlLink(<absolute>) | *Generate URL for file* *If absolute=true, then the final URL looks like - https://example.com/contextPath/rest/site/0/module/0...* *If absolute=false, then final URL looks like - /contextPath/rest/site/0/module/0...* |
| $<File Option Value>.toPublicRedirectLink() | *Generate a public redirect URL for the file* |
| $<File Option Value>.findFirstFileInMediaHolder(<Media Holder Id>) | *Could be used only with a multiple-file field and a related File Option Value* *It allows for getting the first converted File Option Value from a source File Option Value* *For example, source File Option Value image.bmp, then this method returns a converted file from the source(for example, it could be some preview)* |
| $<File Option Value>.findFilesInMediaHolder(<Media Holder Id>) | *Could be used only with a multiple-file field and a related File Option Value* *It allows for getting converted File Option Values from a source File Option Value* *For example, source File Option Value image.avi, then this method returns converted files from the source(for example, it could be some previews)* |
| $tools.base64Encode('<value>') | *Encode the string to base64. Used for generating a link to processed batch on UI* |
| $date.get('yyyy-M-d H:m:s') | *Inserts the action execution date by specified mask, e.g. 2018-3-19 21:54:51* |
| $number.toNumber('#,###,###.###','<number string>') | *Parses a given string and converts it to number* |
| $tools.aesGenerateKey('<password>', '<salt>', <iterations>, <key length>, '<algorithm>') | *Generate a key using the AES key generator. The generated value can be used for encryption/decryption* |
| $tools.aesEncrypt('<value>', '<key>', '<init vector>') $tools.aesEncrypt('<value>', '<key>', '<init vector>', '<cipher name>') | *Encrypt value using key and init vector, optionally cypher name* |
| $danishLocale $usLocale $zuluTimeZone | *Variables for using in date/number formatting* |
| #set($originalDate = ${<Variable With Item>.fieldValue('Added')}) // 25/05/2024, 19:30 - string #set($parsedDate = $date.toDate('dd/MM/yyyy, HH:mm', $originalDate)) // date object $date.format('MMM/dd/yyyy hh:mm a', $parsedDate, $usLocale) // May/25/2024 07:30 PM $date.format('dd/MMM/yyyy HH:mm', $parsedDate, $danishLocale) // 25/maj/2024 19:30 $date.format('yyyy-MM-dd''T''HH:mm:ss.SSSXX', $originalDate.value, $usLocale) // 2024-05-25T19:30:00.000+0200 $date.format('yyyy-MM-dd''T''HH:mm:ss.SSS''Z''', $originalDate.getValue(), $usLocale, $zuluTimeZone) // 2024-05-25T17:30:00.000Z #set($originalDecimal = ${<Variable With Item>.fieldValue('Decimal')}) // 12.345.678,90 - string #set($parsedDecimal = $number.toNumber('###,###.00', $originalDecimal, $danishLocale)) // number object $number.format('###,###.00', $parsedDecimal, $usLocale)} // 12,345,678.90 $number.format('###,###.00', $originalDecimal.value, $danishLocale)} // 12.345.678,90 | *Examples of using locales/timezone in formatting* |
| #set($multiSelectFieldValues = ${CurrentItem.fieldValues('Multiselect Field Name')}) #set($multiSelectFieldValuesSortedAsc = $collection.sort($multiSelectFieldValues)) #set($multiSelectFieldValuesSortedDesc = []) #foreach($item in $multiSelectFieldValuesSortedAsc) #set($void = $multiSelectFieldValuesSortedDesc.add(0, $item)) #end Multiselect Sorted Default: #foreach($arrValue in $multiSelectFieldValuesSortedAsc)$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Default Reversed: #foreach($arrValue in $multiSelectFieldValuesSortedDesc)$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Id Default: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['id']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Id Asc: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['id:asc']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Id Desc: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['id:desc']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted StringValue Default: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['stringValue']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted StringValue Asc: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['stringValue:asc']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted StringValue Desc: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['stringValue:desc']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Value Default: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['value']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Value Asc: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['value:asc']))$arrValue#if($foreach.hasNext), #end#end Multiselect Sorted Value Desc: #foreach($arrValue in $collection.sort($multiSelectFieldValues, ['value:desc']))$arrValue#if($foreach.hasNext), #end#end | *Examples of sorting for multiple select fields* |
| $tools.aesDecrypt('<enctypted value>', '<key>', '<init vector>') $tools.aesDecrypt('<enctypted value>', '<key>', '<init vector>', '<cipher name>') | *Decrypt value using key and init vector, optionally cypher name* |
| $tools.fetchAll() | *Get a list of all item objects in a batch. Then use the foreach syntax to iterate through items* |
| $tools.fetchFirst() | *Get first item in a batch* |
| $tools.fetchFirst().fieldValue('field name') | *Get the value of the specified field of the first item in the batch* |
| $tools.fetchFirst().fieldValue('field name').fieldValue('field name') | *Get the value of the specified field in the linked module of the first item in the batch (for module link and user field)* |
| $tools.fetchUnique('field name') $tools.fetchUnique('field name', 'sub field name') | *Get all unique items in a batch by a specific field. If the field name is a module link, use the additional subfield name parameter to define a field in the linked module* |
| $tools.report( templateId, 'filterValue', 'customName' ) | *Generate a link to download the XSLT report. 'templateId' - id of the item with template in the Report module. 'filterValue' - a value to filter the report data. The filtering field has to be preconfigured in the report template. 'customNamePrefix' - the name of the report file.* |
| #set($targetPathGrid = "/site/${SiteId}/home/module/${ModuleId}/view/list?batchId=${BatchId}")${LoginUrl}?targetPath=$tools.base64Encode($targetPathGrid) | *Generate link to batch item list in Spreadsheet view using the predefined variable and standard bulk operation placeholders* |
| #set($targetPathGallery = "/site/${SiteId}/home/module/${ModuleId}/view/gallery?batchId=${BatchId}")${LoginUrl}?targetPath=$tools.base64Encode($targetPathGallery) | *Generate link to batch item list in Gallery view* |
| #set($customValue = "$tools.fetchFirst().fieldValue('Campaign')") #set($customName = "Report_$date.get('yyyy-M-d H:m:s')") ${SiteUrl}/<worker>$tools.report( 26, $customValue, $customName) | *Generate a link to the report file. Report will contain only the items from specific campaign* |
| #set($emails = $tools.fetchUnique('User Link field', 'Email')) $tools.join($emails, ',', true) | *Get the comma-separated list of unique emails from the items in a batch* |
| #foreach($<Variable With Item> in $tools.fetchAll()) $<Variable With Item>.fieldValue('Created By') #end | *Iterate through the batch items and get a value of the 'Created By' field for each item* |
| $tools.fetchFirst().fieldValue('user field').fieldValue('email') | *Get the email for the user field of the first item in a batch. Supported values: 'name', 'login', 'email', 'mobile_email', 'mobile'* |
| $tools.fetchFirst().fieldValue('module link field').fieldValue('field in linked module') | *Get the value from the specified field in the linked module* |
| #set($allItems = $tools.fetchAll()) #foreach($<Variable With Item> in $allItems ) #set($valuesInMultiUserField = $<Variable With Item>.fieldValues('MultiUserField')) #foreach($value in $valuesInMultiUserField) $value.fieldValue('Name') - $value.fieldValue('Email') #end #end | *Get the pair 'Name - Email' for each user in the multiselect User link field for every item in a batch. Nested foreach cycles are used* |

## Related

- [Migrate actions to the Velocity Template Engine from the Encode Engine](/velocity-template-engine.md)
- [Notification Rules](/notification-rules.md)
