Skip to content
HRTEQDocs
Documentation API

DocsAutomation

Automation rules

The rule engine behind routing and deadline chasing: seven trigger types, eleven condition operators, seven action types, the run log, and the ten rules seeded by default.

An automation rule is a trigger, optional conditions, and one or more actions. Rules do the work nobody remembers to do: routing an application to the officer who owns its new stage, creating the task to book a clinic, chasing a passport six months before it expires.

Automation never breaks a write. Rules fire after the operation that triggered them has already committed, outside its transaction, and a failure is caught and recorded rather than propagated. A slow or broken rule cannot hold a database lock or fail a document verification.

Triggers#

TriggerFires whenConfig it accepts
APPLICATION_CREATEDAn applicant is endorsed to a position.
STAGE_CHANGEDAn application enters a new stage.toStageCode restricts the rule to one destination stage.
DOCUMENT_EXPIRINGThe nightly expiry scan finds a verified document approaching its date.daysBefore, and optionally documentTypeCode to target one type.
DOCUMENT_VERIFIEDA document is verified.
CHECKLIST_OVERDUEThe daily automation cron finds a stalled application.staleDays — matches at or beyond the threshold.
PAYMENT_RECEIVEDA payment is recorded.
DATE_APPROACHINGThe daily cron finds a date field nearing.field (a dotted path such as application.expectedDepartureAt) and daysBefore.
Threshold triggers fire once, on the day. DOCUMENT_EXPIRING and DATE_APPROACHING match only when the remaining days equal daysBefore exactly. A 30-day rule fires on day 30 and not on the twenty-nine days after it — which is the difference between a useful warning and an ignored one. CHECKLIST_OVERDUE is the exception: it matches at or beyond its staleDays.

Conditions#

Conditions are optional. When present, all of them must hold — they are ANDed. Each names a dotted field path resolved against the trigger context, an operator, and usually a value.

OperatorTest
eq, neqStrict equality or inequality.
in, notInMembership in an array value.
gt, gte, lt, lteNumeric comparison.
containsSubstring or collection membership.
isSetThe field has a value.
isEmptyThe field is blank.

A rule with no conditions always proceeds to its actions once the trigger and its config match. A rule whose conditions fail is recorded as SKIPPED with the reason, rather than silently doing nothing.

Actions#

ActionEffect
ASSIGN_STAGE_OWNERAssign the application to the role that owns its current stage. This is what makes a handoff land in someone’s queue.
ASSIGN_ROLEAssign to a named role’s queue.
ASSIGN_USERAssign to a specific user.
CREATE_TASKCreate a task with a title, optional description, an assignee role, a due date dueInDays out, and a priority of LOW, NORMAL, HIGH or URGENT.
SEND_EMAILQueue a templated email by templateCode, optionally addressed to the applicant. Sending is handled by the background worker.
NOTIFYCreate an in-app notification with a title and body, optionally scoped to a role.
SET_CHECKLISTMark a checklist item done or not done by code.
`SET_CHECKLIST` can change gate outcomes. Checklist items are what several stage requirements read. A rule that sets one is, indirectly, deciding whether an application may advance. Use it for genuinely mechanical facts, not to route around a requirement you find inconvenient.

The run log#

Every evaluation writes an AutomationRun row with a status of SUCCESS, SKIPPED or FAILED, plus the context and what was performed. A rule that appears to do nothing can be diagnosed rather than guessed at: either it never matched, or it matched and skipped on conditions, or it failed.

A successful run also increments the rule’s runCount, stamps lastRunAt, and writes automation.fired to the audit trail with the trigger and the actions performed. Note the actor on that audit row is null — it was the system, not a person.

The ten seeded rules#

Every new organization gets these. All of them are editable and can be disabled.

Routing and acknowledgement#

RuleTriggerActions
Route to the owning officer on stage changeSTAGE_CHANGEDASSIGN_STAGE_OWNER — makes every handoff explicit.
Welcome new applicationsAPPLICATION_CREATEDEmail the applicant the APPLICATION_RECEIVED template.

Expiry warnings#

RuleTriggerActions
Document expiring within 30 daysDOCUMENT_EXPIRING, daysBefore: 30High-priority Document Officer task due in 14 days, plus the DOCUMENT_EXPIRING email to the applicant.
Passport expiring within 180 daysDOCUMENT_EXPIRING, daysBefore: 180, documentTypeCode: PASSPORTHigh-priority Document Officer task due in 30 days. Fires far earlier than other documents because most destinations require at least six months of passport validity.

Stage-driven work#

RuleTriggerActions
Medical scheduling task on entering MedicalSTAGE_CHANGED, toStageCode: MEDICALHigh-priority Liaison Officer task due in 3 days to book the DOH-accredited clinic, plus the MEDICAL_SCHEDULE email.
Chase the worker balance at Payment StatusSTAGE_CHANGED, toStageCode: FINANCIAL_CLEARANCEHigh-priority Accounts task due in 5 days to reconcile charges and sign the financial clearance, so ticketing is not held up.
Post-arrival check-in after deploymentSTAGE_CHANGED, toStageCode: DEPLOYEDThree Welfare Officer tasks: day-7 and day-30 at normal priority, day-90 at low.

Departure countdown#

RuleTriggerActions
PDOS reminder 7 days before departureDATE_APPROACHING on application.expectedDepartureAt, daysBefore: 7Only when PDOS_COMPLETED is not yet true. Creates an urgent Welfare Officer task due in 2 days — the PDOS certificate is a prerequisite for the OEC, so it cannot slip.
Departure briefing 3 days outDATE_APPROACHING, daysBefore: 3The DEPARTURE_DETAILS email plus an urgent Welfare Officer task to conduct the pre-departure briefing and confirm airport assistance.

Stall detection#

RuleTriggerActions
Nudge stale applications after 21 daysCHECKLIST_OVERDUE, staleDays: 21A normal-priority Recruitment Officer task due in 3 days: review or close the application.

The stale rule is the one that keeps the board honest. An application with no stage movement in three weeks is either blocked on something nobody noticed or should be closed, and both outcomes are better than a card sitting there indefinitely.

When rules run#

Two paths. Write-driven triggers fire inline from the code path that caused them — a stage move fires STAGE_CHANGED immediately after the transaction commits. Date-driven triggers are evaluated by the background worker’s automation cron at 01:30 Asia/Manila, which is also what feeds DOCUMENT_EXPIRING, DATE_APPROACHING and CHECKLIST_OVERDUE. See Notifications and scheduled jobs.

Rules are scoped to your organization and only active rules are considered, so disabling a rule takes effect immediately without deleting its run history.

Rules are configured in the database today. The engine, the seeded rules and the run log are all real. What does not exist is a settings screen for editing them — automation is a writable module for the Owner and System Administrator, but no UI or endpoint exposes it. Changing a rule currently means changing the row.
Was this page helpful?