Workflow automation
Workflow automation lets CRM teams turn record changes and customer events into repeatable follow-up work. A workflow starts from a trigger, checks the trigger record and related records, then runs conditions and actions such as scoring a lead, changing its temperature, sending an email, notifying users, or converting a lead into a deal. The workflow automation designer explains how users create and validate these flows.
Automation model
An automation flow is a saved rule for one CRM document type. It connects an event to a set of ordered steps and can stay as a draft until a user enables it.
The system separates the main concerns:
- Trigger: Defines when a run can start.
- Filter: Narrows which trigger records qualify.
- Condition: Selects a path during the run.
- Relationship: Finds another record that the flow can inspect or change.
- Action: Performs useful work on a selected record.
- Wait: Delays work or waits for a later event.
This model lets one flow react to a CRM event while keeping the work on the correct lead, deal, communication, task, contact, or organization.
Trigger types
Triggers are the entry points for automation. They cover changes to records, time-based work, user-started work, and named CRM events.
| Trigger family | Purpose |
|---|---|
| Record created or updated | React to a new record or a saved change. |
| Field value changed | React once when a chosen field moves between values. |
| Record submitted, cancelled, or deleted | React to a document state change. |
| Manual | Let a user start the flow from a record. |
| Scheduled | Run on a repeating schedule. |
| Date based | Run before or after a date stored on the record. |
| Custom event | React to a named event raised by CRM. |
CRM events include prospect messages sent or received through email or WhatsApp, lead qualification, lead conversion, deal stage changes, deal outcomes, and overdue tasks. Message events can match either a message thread or the linked lead or deal, so a reply can continue the right piece of follow-up work.
References: frontend/…/workflowTriggers.js• L22-158 crm/…/events.py• L24-46 crm/…/events.py• L49-69
Workflow definitions
The definition combines a trigger with filters, record conditions, relationships, and an ordered action graph. A flow can branch on a condition, wait before continuing, and use the result of an earlier action in a later step. The builder keeps editing separate from testing, so a trial run uses the last saved definition rather than unsaved changes.
The builder shows this as a flow graph. A true and false path make decisions visible, while waits can lead to separate event-matched and timed-out paths. The saved definition keeps enough step identity for run history to explain which path ran.
Conditions
Conditions decide whether a step runs. They can compare fields on the current record, test membership or text, check whether a value is present, and group tests with and or or.
A condition can also evaluate a related record set. The flow can ask whether a related record exists, whether none exists, or whether the count meets a comparison. Filters in this form apply to the related records rather than to the source record.
The condition editor provides a readable filter form for common expressions. Expressions that do not fit that form remain valid as text, which prevents the editor from silently changing a hand-written rule.
References: frontend/…/workflowConditions.js• L1-29 frontend/…/workflowConditions.js• L61-72 frontend/…/WorkflowRelatedCondition.vue• L23-74
Record relationships
Record relationships let an automation move from the trigger record to the records that carry the next piece of work. Each reachable record receives an alias, such as trigger or lead, so later conditions and actions can name their target clearly.
CRM exposes relationships for the records most often used in follow-up work:
| Source | Related records |
|---|---|
| Lead | Organization, contacts, communications, tasks, and deals |
| Deal | Communications, tasks, and contacts |
| Communication | Its linked lead or deal |
Some links come from normal CRM references. Others use CRM rules, such as matching a lead’s organization name to an organization or finding contacts by an explicit link or email address. A relationship can point to one record or many records. When one relationship can point to more than one document type, the flow must narrow the target before the builder can offer the correct fields and actions.
An action can also produce a new record for later steps. Lead conversion is the main example: it produces a deal that the rest of the flow can address. The conversion can reuse an existing deal or fail when the lead was already converted, based on the flow's policy.
References: crm/…/relationships.py• L19-40 crm/…/relationships.py• L47-75 crm/…/relationships.py• L82-151 frontend/…/workflowCapabilities.js• L81-133
Scoring and follow-up actions
Actions turn a matched event into a business result. They run against the selected target record and return a result that later conditions or the run trace can use.
CRM actions support the main follow-up needs:
- Adjust a lead score by a bounded amount and record the reason.
- Set a lead temperature to Cold, Warm, or Hot.
- Convert a lead to a deal and choose how to handle an existing conversion.
- Email a lead or deal with a template or direct content.
- Send an in-app CRM notification to selected users.
Scoring is cumulative across runs when flows update a lead over time. A flow can add or remove points within configured bounds, record the reason, and set a temperature from the score. The score update is protected against competing workers so two events do not overwrite each other's result.
The action target does not have to be the trigger record. A communication-triggered flow can update its linked lead, and a deal-triggered flow can score its related lead. This is the link between event handling and practical follow-up work.
References: crm/…/actions.py• L64-123 crm/…/actions.py• L126-201 crm/…/actions.py• L204-269 crm/…/actions.py• L272-345 crm/…/scoring.py• L19-55
Automation lifecycle
Automation work moves from design to validation, then to an enabled run. The system keeps these stages separate so a flow can be reviewed before it changes CRM records or contacts customers.
- A user creates or opens a flow in CRM settings.
- The user chooses the document type, trigger, filters, relationships, conditions, and actions.
- The builder checks required trigger values and action parameters before saving. It also keeps the target record type aligned with each action.
- The user saves the flow and can run a trial against a selected record.
- The user enables the flow only after reviewing its behavior.
- Matching events create background task runs that execute the selected path and record status and errors.
The trial run uses the saved flow. It returns a step trace that the interface can play through, including branch choices and action outcomes. Real runs appear as recent background tasks with their status, target record, start time, and error summary.
Event processing
The event path connects CRM activity to the automation engine. The following diagram shows the high-level movement from a CRM change to recorded follow-up work.
flowchart LR
A[CRM record or customer event] --> B[CRM event trigger]
B --> C[Match document, filters, and correlation]
C --> D[Start automation run]
D --> E{Conditions and waits}
E --> F[Run action on target record]
F --> G[Record step result and run status]
Record updates emit events only for the business changes that matter. For example, lead qualification requires a move to Qualified, deal events include the prior stage, and overdue task events come from an hourly sweep. Email and WhatsApp message events carry identifiers rather than message bodies. They use correlation keys so a flow can wait for the right thread or record.
References: crm/…/events.py• L49-91 crm/…/events.py• L94-155 crm/…/events.py• L158-190 crm/hooks.py• L240-277 crm/hooks.py• L309-317
Related documentation
Read Workflow automation designer for the user-facing design model and the rules that keep a flow valid before it is enabled.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the CRM event names, event payload keys, subject records, and correlation choices aligned for email and WhatsApp events. A mismatch can make a custom-event flow start for the wrong record or fail to match a wait.
- Keep relationship aliases and target document types aligned with action applicability. A flow may save with a source type that differs from the type targeted by a later step.
- Keep action output fields stable when conditions read prior step results. Scoring, conversion, and branching flows depend on those output names.
- Keep trigger requirements aligned between the trigger picker, builder validation, and run-time checks. A flow with a missing field, date, schedule, or event must not become runnable.
- Review scheduler behavior when changing overdue-task events. The sweep uses a bounded lookback to avoid creating a large batch of stale runs.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A flow is enabled without a complete trigger or action | The flow cannot start correctly or a step cannot run | Builder validation requires trigger details and required action parameters. |
| A relationship can resolve to more than one document type | Fields and actions for the target remain unknown | Narrow the relationship target before configuring dependent steps. |
| A flow scores on every record save instead of a real field transition | The score is added more than once for the same business event | Use a field-change trigger for one-time transition scoring. |
| An email action targets a lead or deal without an email address | The run fails at the email step | Check the target record and use a condition when email is not guaranteed. |
| A wait uses the wrong event or correlation key | The wait times out and follows the timeout branch | Match the event and correlation choice to the thread or record that should reply. |
| A scheduler is off for longer than the overdue-task lookback | Very old overdue tasks are not emitted as new automation events | Treat overdue automation as a current follow-up signal rather than a full historical replay. |
Key files
| File | Why to read it |
|---|---|
| crm/…/events.py | Defines the CRM events that start or resume automations. |
| crm/…/relationships.py | Explains how flows move between leads, deals, communications, tasks, contacts, and organizations. |
| crm/…/actions.py | Shows the business work that an automation can perform. |
| crm/…/scoring.py | Defines lead score and temperature changes used by scoring flows. |
| crm/hooks.py | Connects CRM events, relationships, and actions to the automation engine. |
| frontend/…/WorkflowAutomationPage.vue | Shows how users list, enable, duplicate, and remove workflow automations. |
| frontend/…/WorkflowAutomationBuilder.vue | Shows the design, validation, save, and trial-run stages. |
| frontend/…/WorkflowTrialRun.vue | Shows how a saved flow is tested and how its step trace is presented. |
| frontend/…/WorkflowAutomationRuns.vue | Shows the run status and error information available to users. |
| crm/…/reference_flows.py | Gives complete examples of welcome, scoring, routing, conversion, and stalled-deal automations. |