FAQs: Custom Function

FAQ: Custom Function

What is a custom function?
Custom functions are scripts written in Deluge — Zoho's proprietary scripting language — that allow administrators to define bespoke logic for automating support workflows. They go beyond the standard automation actions (such as alerts, tasks, and field updates) by enabling complex operations like syncing data with external systems, performing conditional logic, updating records across modules, or triggering API calls to third-party services.

Custom functions can be deployed through multiple channels: they can be associated with workflow rules to execute when specific conditions are met, linked to custom buttons on the ticket detail page for on-demand execution, or scheduled to run at specific times or recurring intervals through the Schedules feature.
How to create a custom function?
To create custom functions:
  1. Navigate to Setup > Developer Space > Functions.
  2. Click New Function in the top-right corner.
  3. Under Basic Information, enter a Name and Description for the function, and select the Module in which the function should be triggered. Functions are module-specific, so the module determines the context and the data for the script.
  4. Under Argument Mapping, provide a Method Name and define the arguments the function will use. For each argument, enter an Argument Name and select the corresponding value from the available options. Add more arguments by clicking the + icon.
  5. Write the required logic in the Deluge Script Editor — either manually or using the Zia Deluge Assistant.
  6. Click Save to store the function for later use, or Save & Execute Script to validate and run it immediately.
What is argument mapping?
Argument mapping is the process of defining the input values that a custom function works with at runtime. When creating a function, the user specifies a **Method Name** and then defines one or more **Arguments**, each consisting of an argument name and a mapped value. These mapped values are typically drawn from ticket fields, contact details, or other record properties and are passed into the Deluge script as variables.

For example, if a function needs to update a ticket’s status based on its priority, the user can map arguments for the ticket ID and priority field so that the script receives the correct values when it executes. Without proper argument mapping, the function cannot access the contextual data required to perform its logic.
How can custom function scripts be generated?
Yes. Zoho Desk offers the Zia Deluge Assistant Bot, an AI-powered tool that generates Deluge scripts based on plain-language prompts. Instead of manually writing and debugging code, the user can describe the automation requirements in natural language, and Zia generates a complete script block that can be reviewed, refined, and deployed.

To generate custom function script using Zia:
  1. Open the Deluge Script Editor while creating or editing a function.
  2. Click the Zia icon at the bottom-right corner of the editor.
  3. Enter the requirement as a prompt and click the Send icon.
  4. Review the generated script. If it meets the requirements, click the Copy icon and paste it into the Deluge Script Editor.
  5. Manually edit the pasted script to fine-tune the logic if needed.
  6. Click Save or Save & Execute Script.
If the initial output does not achieve the desired result, the user can refine the prompt and regenerate the script. The Zia Deluge Assistant can generate scripts for both standard and custom modules, adapting to the module selected during function creation.

To enable the Zia Deluge Assistant:
  1. Navigate to Setup > Zia > Generative AI.
  2. Enable the Deluge Assistant Bot under Feature Preferences.
  3. Accept the data usage disclosure for AI.
How to deploy a custom function so that it executes automatically when certain conditions are met?
The most common deployment method is through workflow rules. When creating or editing a workflow rule, the user can associate a custom function as one of its actions:

  1. Navigate to Setup > Automation > Workflows.
  2. Click Create rule or edit an existing one.
  3. Complete the Basic Information, Execute On, and Criteria sections to define when the rule should trigger.
  4. In the Actions section, click the Add + icon and select Custom Function from the drop-down list.
  5. Choose an existing custom function or create a new one.
  6. Click Save.
Once associated, the function executes automatically whenever the workflow rule's trigger conditions and criteria are met. An existing custom function can also be associated with multiple workflow rules, allowing the same logic to be reused across different automation scenarios.

Can a custom function be triggered manually from a ticket without waiting for an automated rule?
Yes. Custom functions can be linked to custom buttons on the ticket detail page, allowing agents to execute specific logic on demand. When an agent clicks the button, the associated custom function runs immediately, and an acknowledgment message confirms successful execution along with the button name.

To set up a button to trigger custom function:
  1. Navigate to Setup > Customization > Buttons.
  2. Click New Button.
  3. Enter a Button Name and Description. The Tickets module is selected by default.
  4. Under Button Properties, choose Detail View PageMore Actions as the location and select a layout.
  5. Under Actions, select Existing Custom Function to link an existing function or New Custom Function to create one. When creating a new function.
  6. Provide the Argument mapping.
  7. Enter the Script.
  8. Click Save.
  9. Under Profile Permission, select the profiles that can view and use the button.
  10. Click Save to save the configuration.
Custom buttons can currently be created only for the Tickets module and placed on the Ticket Detail page under the More option. By default, only administrators can create buttons

To enable this capability for other profiles:
  1. Navigate to Setup > User Management > Profiles
  2. Enable the Button permission under Administrative Permissions.
Can a custom function be scheduled to run at specific times or on a recurring basis?

Yes. Through the Schedules feature, the user can associate a custom function with a time-based trigger:

  1. Navigate to Setup > Automation > Schedules.
  2. Click New Schedule.
  3. Provide a Schedule Name and Description (optional).
  4. Use Execute On to define the date and time for the first run.
  5. Under Repeat, choose the frequency:
    1. Never
    2. Every Hour
    3. Every Day
    4. Every Week
    5. Every Month
    6. Every Year
    7. Custom
  6. Click Associate Function to link an existing custom function, or Create Function to create a new one using the Deluge Script Editor.
  7. Click Save.
Scheduled functions are subject to certain limits: the start date must be within one year of the current date, functions must not exceed 10,000 lines of execution, and each function must complete within 5 minutes. A maximum of 250 active schedules can exist across the entire account, with up to 10 schedules per department. The user can also manually trigger a scheduled function using the Run Now option, which is limited to twice per day per schedule and is available only for active schedules.
How can a custom function be tested and validated before deployment?

A custom function can be tested and validated using the Deluge Script Editor before it is deployed for use. When creating or editing a function, two options are available after writing the script:

 

  1. Save — Saves the function without executing it, allowing the user to review and edit the script later.
  2. Save & Execute Script — Immediately validates and runs the script, allowing the user to verify that the function works as intended in Zoho Desk.

For functions developed as part of an extension on the Sigma platform, the user can test the function from the Functions tab on the Extension Details page. Select the function, choose an organization from the drop-down list, enter the required argument values, and click Save & Execute.

 

Syntax errors are highlighted when the code is saved, while runtime errors are displayed when the script is executed. This allows the user to identify and resolve issues before deploying the function.
What happens when a custom function fails during execution?
When a custom function associated with a workflow rule fails during execution, the failure is recorded in the Ticket History along with the rule name, action name, status, and reason for the failure.

Common failure scenarios include:
  1. Deleted or deactivated agents: If the function references an agent or team that no longer exists, such as in an Assign Ticket or Add Follower action, the function fails. The user must update the function to reference a valid agent or team.
  2. Insufficient permissions: If the user who created the function does not have the required profile permissions to perform an action, the function fails. This can affect all actions associated with the workflow rule. Functions should be created by users with the appropriate permissions.
  3. Deleted placeholder fields: If a custom field used as a placeholder in the function is deleted, the function cannot execute and is disabled. To re-enable it, the user must remove the placeholder referencing the deleted field and save the function again.
If a value passed to the function is null at runtime, the specific execution may be skipped without generating a failure record in the Ticket History, depending on the action type.
Can a custom function be reused across multiple automation scenarios?
Yes. A custom function can be reused across multiple automation scenarios once it has been created and saved. The same function can be associated with workflow rules, custom buttons, and schedules, eliminating the need to duplicate the same logic across different automation configurations.
  1. Workflow rules: Select Existing from the actions drop-down list and choose the previously created custom function.
  2. Custom buttons: Select Existing Custom Function to link an existing function.
  3. Schedules: Associate an existing custom function with the schedule.
For functions developed as part of extensions on the Sigma platform, the same function can also be included in multiple extensions by associating it with each extension individually. The ${LATEST} version tag can be used when associating functions with extensions to ensure that the latest version of the function is used.
What limitations should be considered when working with custom functions?
Custom functions have certain limitations depending on how they are created and deployed:
  1. Scheduled functions: Must not exceed 10,000 lines of execution and must complete within 5 minutes. The start date cannot be more than one year from the current date. An account can have up to 250 active schedules, with a maximum of 10 schedules per department.
  2. Workflow rules: Custom functions are one of the available workflow actions. For modules other than Tickets, only workflow alerts and custom functions can be associated. Tasks and field updates are limited to the Tickets module.
  3. Custom buttons: Can only be created for the Tickets module and placed on the Ticket Detail page. Non-administrator profiles must be granted the required button permissions.
  4. Extension functions: For functions developed on the Sigma platform, the return type must be String. Functions can be tested with specific argument values before deployment.
  5. Module-specific functions: Custom functions are created for a specific module, which determines the available placeholders and data references.