Run Function
The Run Function block executes a custom JavaScript (Node.
Run custom JavaScript or Python functions in workflows
The Run Function block executes a custom JavaScript (Node.js) or Python (Pyodide) function as a step in a MindStudio workflow. It is configured with a function ID that maps to a specific function definition, along with a key-value configuration object that supplies any parameters the function needs at runtime. This makes it possible to perform programmatic operations — such as calculations, data formatting, string validation, or generating charts — directly within a workflow.
The block supports two transition modes. In controlled mode, execution always proceeds to a single designated next block via the defaultTransitionId. In dynamic mode, the function itself is responsible for returning the ID of the next transition, allowing branching logic based on the function's output. Any changes to workflow variables must be made by setting or overwriting them from within the function, as the block does not return values in the conventional sense.
This block fits into workflows that require logic or data manipulation beyond what declarative, no-code blocks can express. It is commonly used alongside AI model blocks, scraping blocks, and data transformation steps — for example, to process structured data returned by an AI model, compute derived values, or generate a chart from collected results.
What you can build
Real-world workflows powered by the Run Function block.
Calculate Numeric Results
Run a JavaScript or Python function to perform arithmetic or statistical calculations on workflow variables, such as totaling line items or computing averages.
Validate and Clean Strings
Use a function to validate user-submitted text — checking format, trimming whitespace, or normalizing casing — before passing the value to downstream blocks.
Generate Charts from Data
Produce Chart.js visualizations from structured data collected earlier in the workflow, then upload the resulting image for display or export.
Search Google Programmatically
Trigger a Google search from within a function using built-in helper access, then pass the results to an AI model block for summarization or extraction.
Dynamic Workflow Branching
Write a function that evaluates workflow state and returns a transition ID, routing execution to different downstream blocks based on computed conditions.
Upload Generated Files
Use a function to programmatically generate a file or image and upload it via the built-in helper, making it available as a workflow output or attachment.
Ready to add Run Function to your workflow?
Get Started FreeCommon questions about Run Function
What are the required parameters for the Run Function block?
The block requires a functionId, which identifies the function to execute, and a transitionType set to either 'dynamic' or 'controlled'. If transitionType is 'controlled', a defaultTransitionId must also be provided. An optional configuration object supplies key-value pairs that the function consumes at runtime.
What does the Run Function block return?
The block does not return values directly. Any data produced by the function must be written back to workflow variables from within the function itself. In dynamic transition mode, the function returns the ID of the next transition block.
What is the difference between dynamic and controlled transition types?
In controlled mode, the workflow always moves to the block specified by defaultTransitionId after the function runs. In dynamic mode, the function is responsible for returning the ID of the next transition, enabling conditional branching based on the function's logic.
What languages can be used in a custom function?
Custom functions can be written in JavaScript (Node.js) or Python (Pyodide).
What kinds of workflows commonly use the Run Function block?
It is used in workflows that require programmatic logic such as calculations, string validation, data formatting, chart generation, Google searches, or conditional branching — tasks that go beyond what declarative no-code blocks can handle on their own.
Related capabilities
Start
Specifies how the workflow is invoked
User Input
Prompt the user for one or more pieces of data that will be saved as a variable. Can include text, multiple choice, images, or files.
Chat
Start a chat session with an LLM.
End
End the workflow. Optionally return a structured output (for API) or send notifications.
Jump
Transition to another workflow, maintaining the same scope
Menu
Present the user with a menu and transition to the next step based on their choice
Add Run Function to your workflow
Build powerful AI workflows with drag-and-drop blocks. No coding required.