Unlock advanced automation capabilities within your workflows by running custom JavaScript or TypeScript in the Execute Code action. This feature lets you implement complex logic, transform data dynamically, connect with third-party systems, and use embedded Admin Assist to generate and refine code from natural-language prompts inside the editor.
Understand the power of custom scripts
By incorporating custom code into your workflows, you gain granular control over your automation processes. You can:
Implement complex business logic: Execute sophisticated conditional logic that goes beyond standard workflow conditions.
Transform data on the fly: Modify inputs, reformat data, or prepare data structures for subsequent actions or external systems. You can leverage dynamic values from requests using data pills and placeholders.
Integrate with external services: Make API calls to third-party systems, fetch data, or trigger actions in other platforms directly from your script.
Use connected app functions: Call
Workflow.*functions for integrated apps such as Jira, Slack, Okta, and Azure AD.
For instance, imagine you're automating new employee onboarding and need to create user accounts in Okta. A custom script can automatically check if a proposed username already exists. If it does, the script can intelligently modify the username (e.g., changing "[email protected]" to "[email protected]") before proceeding with account creation. This proactive approach helps prevent errors and significantly reduces manual intervention.
Set up a workflow to use the Execute Code action
To add custom JavaScript or TypeScript to a workflow, follow these steps:
Navigate to Settings > Your workspace > Workflows. You can find more details on general workflow creation in our article on setting up workflows.
Click the Create a workflow button or select an existing workflow to edit.
Enter a name and description for your workflow if creating a new one.
Configure a trigger for your workflow, such as Request is created. Triggers determine when your workflow will run.
Click on Add an action (or the + icon) to add a new step to your workflow.
From the list of available actions, select Execute code under Core Utilities.
In the action configuration panel, navigate to the Code tab.
Use the Input Data tab to define key-value inputs with static values or placeholders from the trigger and earlier actions. These values are available in your script through the
inputobject, and you can switch to the Code tab to write or generate your JavaScript or TypeScript.Enter or paste your custom JavaScript or TypeScript into the editor. You can also use
Workflow.*functions from connected integrations such as Jira, Slack, Okta, and Azure AD. TypeWorkflow., press Cmd+I or Ctrl+I, or click Insert function to browse the built-in function library.Once you have added your script, click Done to save the action.
Generate code with Admin Assist
In the code editor, click the AI sparkle icon or Generate with AI to open Admin Assist. Describe the code you want in natural language to the coding agent, and continue the conversation to refine the result until it matches your workflow.
Admin Assist inserts the last generated code block into the editor, so you can review it, test it, and continue editing it manually if needed.
Subsequent actions in workflows can consume and use the JSON output data from this action.
After configuring all triggers, conditions, and actions, click Publish at the top right corner to activate your workflow.
Use the full-screen editor
Select the expand icon to open the full-screen editor. The left panel shows the function library, the center panel contains the Input Data and Code tabs, and the right side opens a toggleable Admin Assist panel for AI-generated code.
Test code before publishing
Use Setup test data or Run test to open the test panel for the action. Add sample values for your inputs, then review the output, console logs, and any errors in the test results. After a successful test run, the returned output can be used as placeholders in later workflow actions.
Key Considerations:
Data Access: Your scripts can interact with workflow data using data pills and placeholders to dynamically pull request details or outputs from previous actions.
External Calls: When integrating with third-party systems, ensure your script handles API calls, authentication, and responses appropriately. You can utilize webhook functionalities within your script logic.
Return Value: Your code must return a JSON object so its output can be used as placeholders in downstream workflow actions.
Error Handling: Implement robust error handling within your JavaScript or TypeScript to manage unexpected situations and prevent workflow failures. Failed code actions stop the workflow unless you open the action's Settings tab and choose Continue workflow.
Executing custom JavaScript or TypeScript gives you flexibility to tailor workflows to your exact needs. You can write code manually, generate it with Admin Assist, test it with sample data, and use the output to power later workflow steps.
For more information on related workflow capabilities, explore these articles:
Troubleshoot common issues
Invalid return value: Return a JSON object, not a string, number, array, or undefined value.
Empty response: Confirm that your code includes a
returnstatement that returns a non-null object.Output too large: Reduce the amount of data your code returns and keep only the values later actions need.
Runtime failure: Check for syntax errors, unhandled exceptions, or long-running code.
Admin Assist panel errors: If the AI panel shows an error, verify network connectivity and try again.
Too many active agents: Wait for the current AI generation to finish before starting another one.
Test and production differences: Test runs use the current admin's credentials, while workflow runs use a workspace admin's credentials. Confirm that integrations and placeholders are configured for the runtime environment.
Learn more
For broader workflow generation and editing with natural-language prompts, see Build Workflows with Admin Assist.
