Create a custom workflow node
See the built-in reference for the definition fields and available built-ins.
Register an action that extracts a title
An action consumes the incoming payload and returns its output for the next node.
python
from typing import Any
from bloomerp.automation.base_executor import BaseExecutor
from bloomerp.automation.registry import WORKFLOW_NODE_REGISTRY, WorkflowNodeDefinition
class ExtractTitleExecutor(BaseExecutor):
'''Project the incoming title into a small output object.'''
def execute(self, trigger_data: dict[str, Any]) -> dict[str, str]:
'''Return the incoming title as text.'''
return {"title": str(trigger_data.get("title", ""))}
extract_title = WorkflowNodeDefinition(
id="EXAMPLE_EXTRACT_TITLE",
type="ACTION",
name="Extract title",
description="Copy the incoming title into the output.",
executor_cls=ExtractTitleExecutor,
)
WORKFLOW_NODE_REGISTRY.register(extract_title.id, extract_title)Give a workflow action a configuration form
The workflow editor uses the executor’s form to collect the amount. The executor resolves it against the current input.
python
from typing import Any
from django import forms
from bloomerp.automation.base_executor import BaseExecutor
from bloomerp.automation.registry import WORKFLOW_NODE_REGISTRY, WorkflowNodeDefinition
class AddDaysConfig(forms.Form):
'''Collect the number of days to add to a numeric input.'''
days = forms.IntegerField(min_value=0, initial=1)
class AddDaysExecutor(BaseExecutor):
'''Add a configured number of days to an incoming day count.'''
config_form = AddDaysConfig
def execute(self, trigger_data: dict[str, Any]) -> dict[str, int]:
'''Return the adjusted day count.'''
config = self.resolve_config(trigger_data)
return {"days": int(trigger_data["days"]) + int(config["days"])}
add_days = WorkflowNodeDefinition(
id="EXAMPLE_ADD_DAYS",
type="ACTION",
name="Add days",
description="Add a configurable amount to a day count.",
executor_cls=AddDaysExecutor,
)
WORKFLOW_NODE_REGISTRY.register(add_days.id, add_days)