Sub Process in Softyflow
Subprocesses in Softyflow allow you to modularize your workflow by calling other processes from within a main process. This enables better organization, reusability, and the ability to run multiple instances in parallel.
Overview
A subprocess is a BPMN element that represents the execution of another complete process within the current process flow. When the execution reaches a subprocess element, Softyflow:
- Pauses the current process
- Launches the specified subprocess with the provided variables
- Waits for the subprocess to complete
- Resumes the parent process with the subprocess results
Configuration
Basic Subprocess Configuration
To configure a subprocess in the Process Modeler:
- Select the Subprocess Element: Click on the subprocess element in your BPMN diagram
- Configure Sub Process Settings: In the widget configuration panel, expand the "Sub Process Configuration" section
- Choose the Process: Select the process you want to execute as a subprocess from the dropdown
Subprocess Selection
The subprocess dropdown shows all available processes in your project:
- Process names are displayed for easy identification
- Only processes within the same project are available
- The selected process will be executed with the current process variables
Variable Passing
Input Variables
When a subprocess is launched, it receives:
- All current process variables: The complete variable context from the parent process
- Special variables:
SF_mode
: The execution mode (test/prod)SF_version
: The version IDSF_initiator
: The user who initiated the parent processSF_loop_variables
: Contains the current array element data in multi-instance executionSF_loop_index
: Contains the current iteration index (0-based) in multi-instance execution
Output Variables
When a subprocess completes, its results are passed back to the parent process:
SF_sub_process_data
: Contains the final variables from the subprocessSF_sub_process_res
: Array containing results from multiple subprocess instances (for parallel execution)
Variable Merging
// In the parent process, subprocess results are merged:
if(key == "SF_sub_process_data"){
let SF_sub_process_res = instance.variables[currentActivity.variables]["SF_sub_process_res"]
if(!Array.isArray(SF_sub_process_res)) {
instance.variables[currentActivity.variables]["SF_sub_process_res"] = [variables[key]];
} else {
instance.variables[currentActivity.variables]["SF_sub_process_res"].push(variables[key])
}
}
Parallel Multi-Instance Execution
Softyflow supports parallel execution of subprocesses using BPMN Multi-Instance Loop Characteristics.
Configuration
- Enable Multi-Instance: Configure the subprocess element with Multi-Instance Loop Characteristics
- Set Parallel Array: Specify a variable that contains an array of values
- Configure Array Variable: Each array element will be used to start a separate subprocess instance
Parallel Array Setup
In the subprocess configuration:
- Parallel Array Field: Enter the name of a variable containing an array
- Variable Usage: Each array element becomes available as
SF_loop_variables
in the subprocess - Index Access: The current array index is available as
SF_loop_index
// Example: If you have a variable 'userList' with multiple users
let userList = [
{ name: "John", email: "john@email.com" },
{ name: "Jane", email: "jane@email.com" },
{ name: "Bob", email: "bob@email.com" }
];
// Each subprocess instance will receive:
// SF_loop_variables: { name: "John", email: "john@email.com" } (for instance 1)
// SF_loop_index: 0 (for instance 1)
Important Notes
- Variable Name Only: Don't use
{{}}
or${}
syntax in the array field - just the variable name - Array Validation: If the variable is not an array, Softyflow treats it as a single-element array
[{}]
- Parallel Execution: All subprocess instances run simultaneously
- Result Collection: Results from all instances are collected in
SF_sub_process_res
array
Use Cases and Examples
1. Document Approval Subprocess
Parent Process: Document submission and final approval Subprocess: Individual reviewer approval process
// Variables passed to approval subprocess
{
document: { id: "doc123", title: "Project Proposal" },
reviewer: "john.doe@company.com",
deadline: "2024-01-15"
}
// Subprocess returns
{
approved: true,
comments: "Looks good, approved",
reviewedAt: "2024-01-10T14:30:00Z"
}
2. Parallel User Notifications
Parent Process: System maintenance notification Subprocess: Individual user notification process
// Array for parallel execution
let notificationList = [
{ userId: "user1", method: "email", priority: "high" },
{ userId: "user2", method: "sms", priority: "medium" },
{ userId: "user3", method: "push", priority: "low" }
];
// Each subprocess instance handles one notification method
// Results collected in SF_sub_process_res array
3. Data Processing Pipeline
Parent Process: Data import orchestration Subprocess: Individual file processing
// Files to process in parallel
let filesToProcess = [
{ filename: "data1.csv", type: "customer" },
{ filename: "data2.csv", type: "product" },
{ filename: "data3.csv", type: "order" }
];
// Each subprocess processes one file type
// Results aggregated for final reporting
Best Practices
1. Variable Naming
- Use clear, descriptive names for subprocess variables
- Prefix subprocess-specific variables to avoid conflicts
- Document expected input and output variables
2. Error Handling
- Implement error handling in both parent and subprocess
- Use boundary events for timeout scenarios
- Consider retry mechanisms for failed subprocess instances
3. Performance Considerations
- Limit parallel subprocess instances to avoid resource exhaustion
- Monitor subprocess execution times
- Use appropriate timeout values for long-running subprocesses
4. Testing
- Test subprocesses independently before integration
- Use test mode to validate variable passing
- Verify parallel execution behavior with different array sizes
Monitoring and Debugging
Instance Tracking
Softyflow provides tools to monitor subprocess execution:
- Parent-Child Relationships: View the relationship between processes in the instance details
- Execution Status: Monitor the status of each subprocess instance
- Variable Flow: Track how variables are passed and modified
Common Issues
- Variable Not Found: Ensure the array variable exists and is properly named
- Subprocess Not Starting: Verify the subprocess ID and permissions
- Performance Issues: Monitor parallel execution limits
- Variable Conflicts: Use unique variable names to avoid overwrites
Advanced Configuration
Conditional Subprocess Execution
Use gateway conditions to execute subprocesses conditionally:
// Gateway condition example
{{ approvalRequired }} == true && {{ documentType }} == 'contract'
Dynamic Subprocess Selection
Use variables to dynamically select which subprocess to execute:
// Dynamic subprocess ID
{{ 'process_' + documentType + '_approval' }}
Timeout Configuration
Configure timeouts for subprocess execution using boundary timer events:
- Timer Duration: Set appropriate timeout values
- Timeout Actions: Define what happens when subprocess times out
- Escalation: Implement escalation procedures for delayed subprocesses
Conclusion
Subprocesses in Softyflow provide powerful capabilities for:
- Modularization: Breaking complex processes into manageable components
- Reusability: Using the same subprocess in multiple parent processes
- Parallel Processing: Executing multiple instances simultaneously for improved performance
- Maintainability: Easier updates and testing of individual process components
By following the configuration guidelines and best practices outlined in this documentation, you can effectively leverage subprocesses to build robust, scalable workflow solutions in Softyflow.