Reusable Functions let you create business logic once and use it across multiple processes. This approach reduces code duplication, improves maintainability, and ensures consistency across your FlowX applications.

What are Reusable Functions?

Reusable Functions are self-contained business logic components that process data according to your specified rules. Instead of writing the same logic multiple times across different processes, you can:
  • Define the logic once in a reusable function
  • Use the function in multiple processes through data mapping
  • Automatically propagate updates to all instances when you modify the function
Functions execute in isolated environments and cannot be edited within individual process contexts. All changes must be made to the original function definition.

Key benefits

Reduce duplication

Write business logic once and reuse it across multiple processes

Improve maintainability

Update logic in one place and automatically apply changes everywhere

Ensure consistency

Standardize business rules across your entire application

Increase efficiency

Spend less time rewriting similar logic for different processes

Before you begin

Make sure you have:
  • Access to the FlowX Designer
  • Appropriate permissions to create and manage reusable resources
  • A clear understanding of the business logic you want to implement

Create a reusable function

1

Access the Functions section

  1. In FlowX Designer, go to your project
  2. Navigate to Reusable Resources > Functions
  3. Click the + icon to create a new function
2

Configure basic settings

  1. Enter a descriptive name for your function
  2. Add an optional description explaining the function’s purpose
  3. Click Save to create the function and open the editor
3

Define the data model

  1. Go to the Model tab
  2. Add attributes that your function will work with:
    • Click Add Attribute to create new fields
    • Set attribute types by selecting existing objects from your project
    • Define nested structures as needed
{
  "client": {
    "personalDetails": {
      "firstName": "string",
      "lastName": "string",
      "email": "string"
    },
    "financialDetails": {
      "income": "number",
      "creditScore": "number"
    }
  }
}
4

Configure input parameters

  1. Switch to the Input Parameters tab
  2. Select the fields that your function needs as input
  3. Expand objects to choose specific properties
Define clear input contracts to make your functions truly reusable across different contexts.
5

Set output parameters

  1. Go to the Output Parameters tab
  2. Choose what data the function returns
  3. Select individual fields or entire objects as needed
6

Implement the business logic

  1. Navigate to the Script tab
  2. Choose your programming language (JavaScript or Python)
  3. Write your business logic
// Access input parameters
const firstName = input.firstName;
const lastName = input.lastName;

// Process the data
const client = {
    personalDetails: {
        firstName: firstName,
        lastName: lastName,
        fullName: `${firstName} ${lastName}`
    }
};

// Set the output
output.client = client;
7

Test your function

  1. Go to the Test tab
  2. Add sample data for your input parameters
  3. Click Test to execute the function
  4. Review the output to ensure your logic works correctly
  5. Save your function when testing is successful

Use functions in processes

After creating a reusable function, you can use it in your business processes through Business Rule actions.

Add a function to a process

  1. Open your process definition in FlowX Designer
  2. Select the node where you want to add business logic
  3. Create a new Business Rule action
  4. Select your reusable function from the available options
  5. Configure data mapping between your process and the function

Configure data mapping

Data mapping connects your process data to the function’s input and output parameters.
Map process variables to function input parameters:
Example input mapping
{
  "firstName": "processData.customer.firstName",
  "lastName": "processData.customer.lastName"
}
Ensure data types match between your process variables and function parameters to avoid runtime errors.

Manage functions

View function usage

To see where a function is used:
  1. Select the function in Reusable Resources > Functions
  2. Click the Usages tab
  3. Review all processes and nodes that reference the function
The system displays a resource usage modal when you make changes that might affect existing implementations.

Update functions

When you modify a reusable function:
  • Changes automatically propagate to all instances
  • Existing process instances may need to restart to pick up updates
  • The system preserves instance-specific configurations like data mapping

Change programming languages

You can change a function’s programming language after creation:
  1. Open the function editor
  2. Go to the Script tab
  3. Select a different language from the dropdown
  4. Rewrite your logic in the new language
  5. Test thoroughly before saving
The system shows a usage modal to help you understand the impact of language changes on existing implementations.

Best practices

Design principles

Development workflow

  1. Define data model first: Always establish your data structure before writing code
  2. Specify parameters early: Define inputs and outputs before implementing logic
  3. Use descriptive names: Choose clear, business-oriented function names
  4. Test thoroughly: Validate functions with realistic data before deployment
  5. Handle errors gracefully: Implement robust error handling in your business logic

Organization strategies

  • Group related functions: Organize functions by business domain or use case
  • Follow naming conventions: Establish consistent patterns for function names
  • Document extensively: Include clear descriptions and usage examples
  • Version carefully: Use project versioning to manage function changes safely

Troubleshooting

Common issues

Debugging strategies

  1. Use the test environment: Always test functions thoroughly before deploying to production
  2. Start simple: Build and test functions incrementally rather than implementing everything at once
  3. Use realistic data: Test with data that matches your production scenarios
  4. Verify outputs: Carefully check that function outputs match your expectations
  5. Add logging: Include console output in your function logic to trace execution

Function execution context

Data mapping syntax

When functions execute within processes, they have access to:
  • Input parameters: Mapped from process data according to your configuration
  • Output object: Used to return processed data back to the process
  • Standard libraries: Built-in functions available in JavaScript or Python
  • Error handling: Mechanisms to report execution problems back to the process
Use FlowX expression language for complex data transformations:
// Simple property mapping
"input.firstName": "processData.customer.firstName"

// Nested object access
"input.address": "processData.customer.contactInfo.address"

// Array element access
"input.firstOrder": "processData.orders[0]"

// Conditional mapping
"input.priority": "processData.customer.vip ? 'high' : 'normal'"