Creating and Using Routines

Overview

Routines are modular workflow components that let you encapsulate repeatable, complex, or versionable logic outside of your main workflow tree. Think of them as reusable mini-workflows, like a subroutine in programming, that can be called from any tree, workflow, or other routine.

Using routines helps you:

  • Reduce duplication across workflows
  • Improve maintainability
  • Isolate and test parts of your logic independently
  • Version and evolve processes without breaking parent workflows

When to Use a Routine

Instead of thinking in terms of copying and pasting the same node chains across trees, step back and ask:

  • Is this logic reused across multiple workflows?
  • Does this part of the process need to be versioned separately?
  • Is this section complex or error-prone and would benefit from being isolated?
  • Might this need to be re-run manually or independently of the rest of the process?

If yes is the answer to any of the above, then that’s a great candidate for a routine.


Common Use Cases

Repeating Processes

Any logic that shows up again and again across trees, such as sending notifications, assigning tasks, or updating records, should be abstracted into a routine.

Example: A two-step process to look up a manager and send an approval email.


Error-Prone or External Integrations

If a section of your workflow interacts with an unreliable system, separating it into a routine allows you to:

  • Retry it independently
  • Log failures or fallback behavior
  • Swap in a new integration version without touching the whole tree

Example: A routine that writes to a legacy system with frequent timeouts.


Sub-processes That Deserve Separation

Even if a block isn’t reused, a routine can help manage complexity. This is especially true when:

  • A block has multiple condition paths (e.g., group vs individual approval)
  • The logic needs to be tested or updated on its own
  • Ownership is shared across teams

Example: Group approval vs individual approval paths nested inside a main approval routine.


How Routines Work

  • Inputs: You define the parameters the routine needs (like form values, usernames, or IDs)
  • Nodes: You add tasks, connections, logic just like a tree
  • Outputs: You can return values that the parent workflow can reference

Unlike trees, routines are not tied to external sources. They are purely modular and depend only on what is passed into them.


Creating a Routine

To create a new routine:

  1. Navigate to the Space ConsoleBuild > Workflow > Routines
  2. Click New Routine

You’ll be prompted to fill in the following fields:

  • Name:
    The display name of your routine. Choose something descriptive so others know what this routine does (e.g., "Send Approval Email").

  • Definition ID:
    This is auto-generated by the system and used internally for API calls. You typically don’t need to edit this, but it must be unique.

  • Category:
    Select an existing category to organize your routine. This helps group related logic (like all HR or IT routines).

  • Inputs:
    These are the parameters your routine expects when it's called like form values, usernames, IDs, etc. Each input has:

    • A name
    • A Default Value
    • A description (optional but helpful)
    • A required checkbox
  • Outputs:
    These are the values your routine will return after it runs. For example, a status message, a generated ID, or a calculated result.

Once you've filled everything in:

  1. Click Create Workflow
    This opens the Workflow Builder, where you can add nodes, logic, and connector paths to define what the routine does.



Calling a Routine from a Tree

  1. In your workflow tree, click the + to add a node
  2. Search for and select the routine from the task list (orange bar)
  3. Pass in values for each required parameter
  4. (Optional) Capture return values using <%= @results['Some Value'] %> in downstream nodes


🧠

Tip: Keep routine inputs clean and specific. Don’t over-fetch. Pass only what’s needed for clarity and reusability.


Returning Data from Routines

If your routine produces a value you want to use later (like an approval status, a system ID, or a calculated deadline), you can return it as a result:

  1. Add a Set Result node inside your routine
  2. Set Result Name and Result Value
  3. In your tree, reference the result like:
    <%= @results['Result Name'] %>

Best Practices

  • One purpose per routine, don’t overload it with multiple unrelated tasks
  • Test routines in isolation using the Runs tab for visibility
  • Version carefully, changing a routine affects every tree that calls it
  • Document expected parameters and results in the routine description

What's Next?