Custom functions
Custom functions are server-side steps that pages in your app run. AI Builder proposes them; learn how they run and how they differ in time.
A custom function is a server-side step that a person runs from a page in your app. AI Builder can propose functions in the blueprint and creates them when you generate the app. This article explains what you see in the blueprint and how functions run.
What a custom function is
A custom function is JavaScript that runs on the server inside your app. It reads a few inputs, runs its code, and hands back one result that the page can use. A person runs it from a page, and pages, components, and flow events can call it.
See functions in the blueprint
Open Blueprint > Custom Functions (tab 8). The tab reads: "The server-side steps a person runs from this app's pages. Each one reads a few inputs, runs its code in the background and hands back one result the page can use."
Each card shows:
- The function's name, such as "Find duplicate invoices", and its key, such as
find_duplicate_invoices - What it reads and returns. For example, one input (an array) and two outputs: a count (number) and the duplicates (array)
- SERVER STEP
- Runs from, the page where a person starts it (for example, AP Workbench)
- Code & example run, an expander with Example 1, Example 2, and a Copy button
Interactive and background functions
A function is declared as one of two kinds, set on the function, not by the caller.
| Kind | How it runs | Limit |
|---|---|---|
| Interactive | Answers while the person waits. | Within 30 seconds |
| Background | Queued and runs behind the scenes. | Up to 10 minutes |
The same call runs both. For an Interactive function, the result is already there when the call returns. For a Background function, the call returns a run that is queued, and you fetch the result later or wait for it to finish.
Call a function from a page
Pages and components call a function by its name with kf.app.runFunction. See the Custom Functions SDK reference for the runFunction call and result shapes.
A run's status is Queued, Running, Success, Failed, or TimedOut. For a Background function, use kf.app.getFunctionRun(runId) to read the run, or kf.app.onFunctionRunComplete(runId, callBack, onError) to be told when it stops. "Stops" is not the same as "worked", so read Status before you use Result. See the custom functions SDK reference for all methods and errors.
Note
kf.app exists only inside an app. A form event script stops after 60 seconds, so for a Background function that may take longer, poll from a script that will still be running.
Tips
- Review the code in Code & example run before you generate.
- Choose Background for work that may take longer than 30 seconds, such as a month-end report.
- Test the function in development after you generate.

