Skip to main content

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.AI 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.AI 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
Functions support both primitive data types (string, number, boolean) and complex object data types for input and output parameters.
  • Primitive data model
  • Object data model
Simple data types for straightforward calculations:
{
  "monthlySalary": "number",
  "loanTerm": "number",
  "interestRate": "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 using the appropriate data format
  • Primitive data example
  • Object data example
Simple function that processes primitive data types:
// Function format: functions.projectName.functionName(input)
function functions.academy.calculateMaxLoanAmount(monthlySalary) {
    // Simple calculation
    output = input.monthlySalary * 48;
}
Always use input.attribute format to access function parameters and output.attribute to set return values.
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, or reference it within other reusable functions.

Where you can reference functions

Reusable functions can be referenced in two contexts:
  • Business Rule actions within process nodes
  • Other reusable functions to create composite logic

Function referencing syntax

When referencing a reusable function, use this format:
functions.projectName.functionName(input.params)
Where:
  • functions - Convention to reference any reusable function
  • projectName - Name of the project/library where the function is defined
  • functionName - Name of the reusable function
  • input.params - Input parameters using local process variables
functions.academy.calculateMaxLoanAmount(input.monthlySalary)

Add a function to a process

  1. Open your process definition in FlowX.AI Designer
  2. Select the node where you want to add business logic
  3. Create a new Business Rule action
  4. Reference your reusable function using the syntax above
  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.
  • Input mapping
  • Output mapping
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.

Use functions within functions

You can create composite business logic by calling one reusable function from within another reusable function. This enables you to build complex functionality from smaller, focused components.
1

Reference the function

Use the standard function referencing syntax within your script:
// Call another function and use its output
const maxLoan = functions.academy.calculateMaxLoanAmount(input.monthlySalary);

// Use the result in further calculations
const loanDetails = functions.loanLibrary.calculateLoan({
    principal: maxLoan,
    rate: input.interestRate,
    term: input.loanTerm
});

// Set the final output
output.integratedLoanData = loanDetails;
2

Handle data flow

Ensure proper data flow between functions:
  • Input format: Always use input.attribute to access function parameters
  • Function calls: Use functions.projectName.functionName(parameters) format
  • Output assignment: Set results to output.attribute
3

Test composite functions

Test thoroughly to ensure all nested function calls work correctly:
  1. Test each individual function first
  2. Test the composite function with realistic data
  3. Verify the data flows correctly between function calls
  4. Check error handling when nested functions fail
// Function that calculates loan based on salary using other functions
function functions.loanProject.integratedLoanCalculator(clientData) {
    // Calculate how much loan a person can get based on their salary
    const maxAmount = functions.academy.calculateMaxLoanAmount(input.clientData.monthlySalary);
    
    // Use that amount with calculateLoan function to compute detailed loan information
    const loanDetails = functions.loanLibrary.calculateLoan({
        principal: maxAmount,
        monthlyRate: input.clientData.monthlyRate,
        numberOfPayments: input.clientData.numberOfPayments,
        client: input.clientData
    });
    
    // The final computed result is passed into the output
    output.integratedLoanData = loanDetails;
}
When using functions within functions, ensure all referenced functions exist in your project and have compatible input/output formats.

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

Each function should serve one specific, well-defined purpose. Avoid creating functions that handle multiple unrelated tasks.
Define precise input and output parameters. Well-defined interfaces make functions easier to understand and use correctly.
Functions shouldn’t depend on external state or global variables. All necessary data should come through input parameters.
The same inputs should always produce the same outputs. Avoid non-deterministic behavior in your business logic.

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

Possible causes:
  • Incorrect input parameter mapping
  • Data type mismatches between process and function
  • Missing required input parameters
  • Runtime errors in function logic
Solutions:
  • Verify all input mappings are correct
  • Check data types match between source and target
  • Ensure all required parameters have values
  • Review function logs for error details
Possible causes:
  • Incorrect output parameter mapping
  • Logic errors in function implementation
  • Invalid test data during development
Solutions:
  • Validate output parameter configuration
  • Test function with realistic data
  • Review business logic implementation
  • Check data transformations within the function
Possible causes:
  • Complex data processing logic
  • Inefficient algorithms
  • Large data structures
Solutions:
  • Optimize function algorithms
  • Simplify data models where possible
  • Consider breaking complex functions into smaller components
  • Monitor execution times in process context

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

Function format and syntax

All reusable functions follow a consistent format and syntax:
function functions.projectName.functionName(parameterName) {
    // Function implementation
}
Key format rules:
  • Function declaration: functions.projectName.functionName(parameters)
  • Input access: Always use input.attribute to access function parameters
  • Output assignment: Use output.attribute to set return values
  • Function calls: Reference other functions using functions.projectName.functionName(params)

Data access patterns

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
  • Input format
  • Output format
Access function input using the input.attribute format:
// Access input parameters
const salary = input.monthlySalary;
const client = input.client;
Always verify that your input format (input.attribute) matches the parameter names defined in your function to avoid runtime errors.

Frequently asked questions

Yes, you can change a function’s programming language after creation. Navigate to the Script tab, select a different language from the dropdown, rewrite your logic in the new language, and test thoroughly before saving. The system will show a usage modal to help you understand the impact on existing implementations.
Reusable functions can be referenced in two contexts:
  • Business Rule actions within process nodes
  • Other reusable functions to create composite logic
Use the format: functions.projectName.functionName(input.params)Example: functions.library1.calculateAgeFromSSN(input.client.ssn)Where:
  • functions - Convention to reference a function
  • library1 - Name of the project/library where the function is defined
  • calculateAgeFromSSN - Name of the reusable function
  • input.client.ssn - Input parameters using local process variables
Yes, you can use functions within functions to create composite business logic. Simply reference other functions using the standard syntax: functions.projectName.functionName(parameters) within your function script.
You can use both primitive and object data types as parameters for input and output:Primitive types: string, number, boolean Object types: Complex structures with nested properties, arrays, and custom business objectsFunctions automatically handle the data format based on your model definition.