Skip to main content

Run Code

Olivia Garrahan avatar
Written by Olivia Garrahan
Updated over a week ago

How to set up and use Run Code action

Run custom JavaScript code to perform complex tasks. Follow these steps:

  1. Add a Run Code action: While editing a workflow, click the plus button between existing blocks. This will open a modal where you can select from Cassidy's pre-configured actions. Choose the Run Code action to add it to your workflow.

  2. Rename the action (optional): If you want to make the action more descriptive or easier to reference as a variable later, enter a new name.

  3. Enter custom "JavaScript Code": In the code editor, write your custom code. You can reference variables from previous steps or the trigger using variables. For information on managing secret API keys or any secure information, see Secret Keys. *Variables are inputs from the trigger, or outputs from previous steps.

    *Note: The code is executed in a secure, sandboxed environment. You can use built-in JavaScript functions and objects, but you cannot access external libraries or make network requests.

  4. Use AI to write custom code (optional): Click on the "Generate with AI" button above the code editor:

    Then, enter the prompt for what you want the code to do in the prompt text box. If you need to insert a variable, press "#" to reference a variable. In the below example, "emails" is an input to the workflow that contains a string list of emails:

    Then, click the "Generate" button to generate the code. From the above prompt, clicking "Generate" resulted in this code:

  5. Configure Output Fields: The return value of your JavaScript code will be the output of the action. In the "Output Fields" section, you have two options:

    • Auto-detect from code (recommended): If the "Auto-detect from code" toggle is enabled, Cassidy will analyze the return statement in your JavaScript code to automatically determine available outputs. These detected fields will appear in the "Detected Fields" section and can be referenced in later workflow steps.

    • Define Output Fields manually: If you toggle off "Auto-detect from code", you can manually add fields in the "Define Output Fields" section. Click "+ Add Field" to specify the field name and data type for each output value you want to access in subsequent actions. For more information on defining structured output fields, see Using Structured Output Fields.

  6. Run the workflow: You can run the workflow (in this case you can see the input is 3 emails separated by a comma):

    Here is a sample of the output when using "Run Code" to filter out personal emails:

Did this answer your question?