Skip to main content
Version: Next

PythonScriptActivity

Category: Common Steps Namespace: CMS.Plugin.FlowManagement.Domain.FlowBusiness.Activitys Base Class: ActionActivity Module: FlowManagement.Domain

Overview​

PythonScriptActivity is a node used to execute Python scripts directly within a flow. Inheriting from ActionActivity, it uses the IronPython engine to execute inline Python script code at runtime. This node supports parameter mapping and result extraction, allowing flexible data calculation, transformation, and processing.

Unlike ScriptCallActivity, PythonScriptActivity allows writing Python code directly in the node configuration without pre-configuration in script management, suitable for simple data processing and calculation scenarios.

Business Scenarios​

Applicable Scenarios​

  • Data Calculation: Execute mathematical calculations, statistical analysis, etc.
  • Data Transformation: String processing, format conversion, encoding/decoding
  • Condition Judgment: Complex business rule judgment
  • Data Validation: Data format validation, range checking
  • Rapid Prototyping: Quickly implement and test business logic

Role in the System​

PythonScriptActivity acts as an inline script executor in the LMES flow system:

  • Directly executes configured Python scripts
  • Supports passing parameters from flow context
  • Supports writing execution results back to flow context
  • Uses IronPython engine, compatible with Python 2.x syntax

Configuration Instructions​

Basic Configuration​

Property NameTypeRequiredDefault ValueDescription
ScriptstringYes-Execution script, Python script for calculation
MappingParameterMapCollectionNoEmpty CollectionParameter matching, pass flow parameters as call arguments
ResultParameterResultParameterCollectionNoEmpty CollectionResult parameters, names to store results in flow context
ActionActionTypeNoExecuteExecution timing (Inherited from ActionActivity)
IsSynchronousboolNotrueWhether to execute synchronously (Inherited from ActionActivity)

Configuration Details​

Script​

Description: Python script code to run during flow execution. Script executes using IronPython engine, compatible with Python 2.x syntax.

Value Range: String, valid Python code

Notes:

  • Uses IronPython engine, some Python 3.x features may not be supported
  • Script automatically adds current working directory to sys.path
  • Can use import to import standard libraries and custom modules

Mapping​

Description: Parameter mapping configuration, defining how to pass parameters from flow context to Python script.

Parameter Mapping Model:

  • Source: Parameter name in flow context (Data Source)
  • Target: Variable name in Python script (Target Variable)

Notes:

  • Mapped parameters will be available as Python variables in the script
  • Parameter types are automatically converted to corresponding Python types

ResultParameter​

Description: Result parameter configuration, defining how to write Python script execution results back to flow context.

Result Parameter Model:

  • Name: Variable name in Python script, also the key name written to flow context

Notes:

  • After script execution, value is retrieved from Python scope for the specified variable
  • Results are written to flow context in order

Flow Context​

Input Parameters​

Parameter NameTypeDescription
Mapping.SourceanyParameters passed to script via Mapping configuration

Output Parameters​

Parameter NameTypeDescription
ResultParameter.NameanyResults retrieved from script via ResultParameter configuration

Usage Examples​

Basic Example: Simple Calculation​

{
"Type": "PythonScriptActivity",
"Name": "Calculate Total",
"Alias": "CalcTotal",
"Script": "total = price * quantity",
"Mapping": [
{ "Source": "Price_Value", "Target": "price" },
{ "Source": "Quantity_Value", "Target": "quantity" }
],
"ResultParameter": [
{ "Name": "total" }
]
}

String Processing Example​

{
"Type": "PythonScriptActivity",
"Name": "Format Barcode",
"Alias": "FormatBarcode",
"Script": "formatted = prefix + barcode.zfill(10) + suffix",
"Mapping": [
{ "Source": "Barcode_Value", "Target": "barcode" },
{ "Source": "Prefix_Value", "Target": "prefix" },
{ "Source": "Suffix_Value", "Target": "suffix" }
],
"ResultParameter": [
{ "Name": "formatted" }
]
}

Notes​

  • ⚠️ IronPython Limitations: Uses IronPython engine, some Python 3.x features not supported
  • ⚠️ Performance: New Python engine created for each execution, frequent calls may affect performance
  • ⚠️ Type Conversion: Parameters automatically convert types between .NET and Python
  • ⚠️ Exception Handling: Script execution exceptions interrupt flow, add exception handling in script
  • ⚠️ Security: Scripts can access system resources, note security risks

Update History​

DateVersionDescription
2025-11-281.0Initial version

Last updated: 2025-11-28