Custom functions
This feature is available to Enterprise customers.
Custom functions are created using JavaScript.
You create and manage custom functions in the Functions section.
Custom functions belong to a team. All users with the Team Member role can view and use custom functions. To create and edit custom functions, you need to have the Team Admin role.

To create a new custom function:
In the left sidenav, click Functions.
Click + Add a function.
Enter a name and description. The name and description will appear in the list of functions available in the scenario designer.

Click Save.
Write the code of the function. Use the keyword return to define the return value.

Click Save.
When you save the function for the first time, it immediately becomes available in the scenario designer. Custom functions are marked with an icon to distinguish them from the built-in functions.
The structure of custom functions reflects the structure of regular JavaScript functions. Each function must contain the following:
- Function header - the name of the function and the parameters it accepts.
- Function body enclosed in curly brackets.
- Exactly one return statement.
Custom functions support JavaScript ES6. No 3rd party libraries are supported.
The following limits apply to all custom functions that you create:
- A single custom function can't run for more than 300 milliseconds.
- The code of a custom function cannot have more than 5000 characters.
- Functions must be synchronous. You can't run asynchronous code in your functions.
- You can't make HTTP requests from your functions.
- You can't call other custom functions from inside of a custom function.
- You can't use recursion in your custom functions.
- In order to use a custom variable with an iterator, you need to:
- Set the value with the custom function in a Set Variable module before the Iterator.
- Map the output of the Set Variable to the Iterator.
Every time you save a custom function, the system creates a new history record. This allows you to compare versions and revert your function to a previous version.

Select a history record to compare the function with the previous version. You can only compare two consecutive versions.
Click Restore this version to revert to the version that you're currently viewing. This creates a new version of the function with the content of the restored version.
Built-in functions are available as methods of the iml object.
The following example uses the Length built-in function.
You can execute your custom function code in the debug console, which is located under the code editor.
You can delete your custom functions in the list in the Functions section.

Before you delete a function, click Edit next to it and then switch to the Scenarios tab. Here, you can check in which scenarios the function is used.

When you delete a function that is used in a scenario, the scenario will fail to execute on its next run.
The scenario that uses the deleted function will fail with the following error message:
Failed to map '<field name>': Function '<function name>' not found!
Returns the string "Hello world."
Calculates how many working days there are in the month specified by the month's number and a year in the function's arguments. Does not take into account local holidays.
Calculates the number of days between two dates passed to the function as arguments.
Accepts an array as an argument. Returns a random item from the array.