Resources

Products

Execute functions in AI Agent workflows

Modified on: Thu, 20 Aug, 2026 at 3:57 PM

Functions enable you to transform and process data dynamically within Freshservice AI Agent workflows using JavaScript.

This article provides an overview of pre-built and custom functions, their core capability pillars, and step-by-step instructions for executing them in your workflows.

TABLE OF CONTENTS

Prerequisites

Before you use functions, ensure that the following requirements are met:


  • Ensure that you have administrator access to AI Agent Studio.

  • You have created an AI Agent workflow to process data.

  • You have a basic understanding of JavaScript if you plan to create custom functions manually.


Overview
Functions enable administrators to author and execute JavaScript for inline data transformation, parsing API responses, and evaluating custom business logic in Freshservice AI Agent workflows. 

You can use pre-built functions for common transformations, such as formatting dates, manipulating text, and performing calculations, or create custom functions to implement business-specific logic. Once created, functions can be executed within a workflow to prepare data for conditions, responses, API actions, and other downstream workflow steps.

For example, an external IT asset management API may return full asset details when you only need the warranty expiration date, or you may need to calculate whether a requester is still eligible for an automated hardware upgrade before deciding how the workflow should proceed.

Function workflow

A function accepts one or more inputs, processes them using custom JavaScript code, and returns the result as a JSON object. You can provide inputs collected during the workflow, requester or ticket properties, or output parameters from API actions.

For example, in an asset request workflow, an API action can return the ticket creation date and the hardware delivery date. You can pass these values to a function to check whether the request meets the standard SLA turnaround time.

The function processes the dates and returns the result as shown in the following example:

JSON

{

  "isWithinSLA": true

}


The workflow can then use isWithinSLA in a condition to determine the next step, such as routing the request for express approval.

Types of functions

Freshservice provides two types of functions that you can use in your workflow.

Pre-built functions

Pre-built functions offer ready-to-use operations for standard data processing tasks.These ready-to-use functions cover common transformation scenarios, such as string operations and date formatting, without requiring custom code.

Custom functions

Custom functions allow you to write custom code when standard options do not meet your business logic.

You can write custom JavaScript to implement business-specific transformations that are not available in the default library. A few scenarios where you may use custom functions include:

  • Extracting or transforming information from API responses.

  • Applying business-specific validation rules to check data against Freshservice ticket policies.

  • Performing custom calculations that are not covered by pre-built functions.

  • Creating reusable transformation logic across multiple workflows.

Explore the pre-built function library

The pre-built functions library includes a collection of ready-to-use functions organized by operational category. Instead of writing JavaScript for frequently used operations, you can use these functions directly in your workflows or clone them and customize the logic to meet your requirements.

Google Docs converts HTML line breaks (<br>) into full paragraph breaks with default top and bottom paragraph padding, which causes large vertical white spaces in table cells. Keeping the text inline as continuous paragraphs with bold section tags eliminates extra cell height when pasted.


Calculation functions

Calculation functions execute mathematical operations on numeric data. Use these functions to perform mathematical calculations using values collected during the workflow.


Function

Description

Example

Arithmetic Expression

Evaluates a mathematical expression using one or more numeric values.

Use case: An employee requests 5 additional software licenses. The workflow calculates the total cost as number_of_licenses × per_license_cost and the agent confirms the total. 

Input: number_1 = 5; number_2 = 499; expression = "number_1 * number_2". Output: result = 2495.

Add Numbers

Add two numbers together and return the sum.

Use case: An IT agent calculates the total number of days an employee has been on leave by adding two separate leave periods.
 
Input: number_1 = 5; number_2 = 3. Output: result = 8.



Date and time functions

Date and time functions allow you to format, compare, and calculate time parameters. Use these functions to perform date calculations, compare dates, and convert dates into the required format.


Function

Description

Example

Add Time to Date

Adds a specified duration to a date or time. You can optionally skip weekends when adding days.

Use case: An employee asks when their laptop will be ready. The workflow fetches the request approval date, adds 3 working days (skipping weekends), and the agent shares the expected provisioning date. 

Input: input_date = "10-06-2026"; format = "dd-MM-yyyy"; days = 3; skip_weekends = "Yes". 
Output: result = "15-06-2026".

Get Days Between

Calculates the number of days between two dates. You can optionally exclude weekends.

Use case: An employee submits leave dates through the bot. The workflow calculates the working days between the start and end dates, checks it against the remaining leave balance, and confirms. 

Input: start_date = "01-06-2026"; end_date = "15-06-2026"; format = "dd-MM-yyyy"; skip_weekends = "Yes". 
Output: result = 10.

Compare Dates

Compares two dates and determines whether one date is before, after, or equal to the other.

Use case: An employee asks to enroll in a benefits plan. The workflow compares today's date against the enrollment window end date. If the window has closed, the agent informs them of the next open enrollment period. 

Input: date_1 = "20-06-2026"; date_2 = "30-06-2026"; format = "dd-MM-yyyy". Output: result = -1.

Format Date

Converts a date from one format to another.

Use case: An HR system returns the enrollment end date in ISO format. The workflow converts it into a readable format before displaying it to the employee.

Input: input_date = "2026-06-15T14:30:00Z"; input_format = "yyyy-MM-dd'T'HH:mm:ss'Z'"; output_format = "dd MMM yyyy, hh:mm a". Output: result = "15 Jun 2026, 02:30 PM".

Get Current Date

Returns the current date and time in the specified format and timezone.

Use case: An employee asks if today is the last day to submit investment proofs. The workflow fetches the current date, compares it against the submission deadline, and the agent confirms or alerts accordingly.

Input: format = "dd-MM-yyyy HH:mm:ss"; timezone = "Asia/Kolkata". 
Output: result = "21-06-2026 20:00:00".


Text functions

Text functions allow you to clean, reformat, and combine string values. Use these functions to manipulate, combine, and standardize text before using it elsewhere in the workflow.


Function

Description

Example

Split

Splits a text value using a specified separator and returns the required part.

Use case: An employee provides their employee ID ("ENG-4502") while requesting tool access. The workflow splits it at "-" to extract the department code ("ENG") and determines the default access permissions for Engineering. 

Input: input_text = "ENG-4502"; separator = "-"; index = 0. 
Output: result = "ENG".

Concatenate

Combines two or more text values into a single string.

Use case: The Active Directory API expects usernames in "domain\username" format for a password reset call. The workflow concatenates the domain prefix and the employee's username ("corp\priya.s") before passing it to the API action. 

Input: text_1 = "corp"; text_2 = "priya.s"; separator = "\". 
Output: result = "corp\priya.s".

Uppercase

Converts text to uppercase.

Use case: An employee provides a serial number for a device issue. The workflow converts it to uppercase before querying the asset database, avoiding lookup failures from case variations. 

Input: input_text = "mac-m1-89234". Output: result = "MAC-M1-89234".

Lowercase

Converts text to lowercase.

Use case: An employee types their username as "JDoe" while requesting a password reset. The workflow converts it to lowercase before validating against Active Directory, where usernames are stored in lowercase. 
Input: input_text = "JDoe". 
Output: result = "jdoe".


List functions

List functions assist in extracting elements from arrays and collections. Use these functions to retrieve or extract specific values from lists and API responses.


Function

Description

Example

Extract from List

Retrieves an item from a list using its position. You can optionally extract part of the selected value.

Use case: An employee says "I'm having issues with my laptop.". The CMDB API returns a list of assets assigned to them. The workflow extracts the first entry (primary device) and the agent confirms: "Is this about your MacBook Pro (asset ID BLR-L4502)?". 

Input: input_list = ["MacBook Pro (BLR-L4502)", "Monitor (BLR-M102)"]; index = 0. 
Output: result = "MacBook Pro (BLR-L4502)".


Encoding functions

Encoding functions convert strings between plain text and encoded formats. Use these functions to encode or decode data when working with external APIs.

Function

Description

Example

Base64 Encode

Converts plain text into Base64 format.

Use case: Mid-workflow, an API action requires Basic Auth. The workflow encodes the service account credentials to Base64 before passing them in the Authorization header. 

Input: input_text = "api_user:Xk9$mP2w". 
Output: result = "YXBpX3VzZXI6WGs5JG1QMnc=".

Base64 Decode

Converts Base64-encoded text back to plain text.

Use case: An identity provider returns user attributes as an encoded token in the API response. The workflow decodes it to extract the employee's role and entitlements before proceeding with access provisioning. 

Input: input_text = "eyJyb2xlIjoiYWRtaW4iLCJlbnRpdGxlbWVudHMiOiJmdWxsIn0=". 
Output: result = '{"role":"admin","entitlements":"full"}'.


Custom functions configuration

Custom functions provide flexibility when pre-built functions do not fit specific automation requirements.

The pre-built function library covers many common data transformation tasks. However, in some scenarios, you may need to create logic specific to your business processes.

In these cases, you can create a custom function to process data exactly the way your workflow requires. For more information, see Create and manage custom functions.

Access the functions

The Functions management page allows you to view and manage all function assets in one location. To access the functions, follow these steps:

  1. Go to AI Agent Studio from the left navigation pane.

  2. Under Library, click Functions.

You can see the list of pre-built and custom functions you have created. For more details on managing custom functions, see Create and manage custom functions.

Execute functions in workflows

Functions can be executed at various points in an AI Agent workflow to transform data dynamically. You can use functions in the following ways within the workflow:

  • As a standalone node: Add a function node to process data and use its outputs in subsequent steps.

  • Within other workflow nodes: Use a function as part of the input or parameter configuration when you need to transform or calculate data within other nodes such as:

    • Conditions: Use a function output when evaluating a condition. For example, calculate whether a request is eligible for automated processing before deciding the path the workflow should follow.

    • Custom responses: Use function outputs to personalize the response displayed to the user. For example, format a delivery date before displaying it in a response.

    • API actions: Use functions to transform data mapped to an API action or process an API response before using the result elsewhere in the workflow.

Add a function as a standalone workflow node

Standalone function nodes process data independently as an individual workflow step.

To add a function as a standalone node, follow these steps:

  1. Go to AI Agent Studio > Workflows and select the workflow where you want to add the function.

  2. Click the plus (+) icon and select Execute Function.

  3. Under Choose/Create a Function, select a function from My functions or Pre-built functions. You can preview the function before selecting it.

  4. Under Map inputs to function parameters, select the property type ( Requester, Account or Ticket) and map it to the function parameters.

  5. Click Save.

Note: Before mapping inputs, use a Collect info block to capture them. If already available as requester or ticket properties, map them directly, especially for sensitive information like email or phone number.
`

Add a function within another workflow node

Inline functions transform specific values inside conditions, responses, or API nodes. To add a function within another node, follow these steps:

  1. Go to the workflow node and open the condition, custom response, or API action where you want to use the function.

  2. In the relevant input field, open the content picker.

  3. Select Input/output parameters, and select the required function output.

  4. Complete the configuration and click Save.