Skip to main content

Scheduled report email

The problem​

Management wants yesterday's figures by e-mail at 08:00 on weekdays, without a separate script.

The pattern​

PartMechanism
Compute the figuresA Nomaflow job on a schedule, with a sql_query step that writes them into a report table.
Send themA notification rule on the job's succeeded event, channel email, to a role or addresses.
Show the detailA dashboard or a screen on the report table.

The recipe​

1. The e-mail account​

Liberty Next → Administer → App → Notifications: SMTP server, port, security, account and sender address. Send a test checks it. See Notifications → The e-mail account.

2. The report table and its query​

CREATE TABLE daily_pipeline (
report_date DATE,
stage VARCHAR(30),
deals INTEGER,
amount DECIMAL(14,2)
);

A writable query compute_daily_pipeline on the CRM connector:

INSERT INTO daily_pipeline (report_date, stage, deals, amount)
SELECT CURRENT_DATE - 1, stage, COUNT(*), SUM(amount)
FROM deals
WHERE updated_at >= CURRENT_DATE - 1 AND updated_at < CURRENT_DATE
GROUP BY stage

3. The job​

In Nomaflow, a job crm-daily-pipeline with:

  • a schedule 0 8 * * 0-4 — 08:00 Monday to Friday (in Liberty Next's cron, day 0 is Monday; see Schedules → Cron);
  • a sql_query step running compute_daily_pipeline.

Run now checks it at once. See Create a job.

4. The e-mail​

Liberty Next → Build → Notifications, a new rule:

FieldValue
TriggerA job event, job crm-daily-pipeline, event succeeded.
Channelsemail (and portal for the bell).
Recipientsrole:management, or email:management@example.com.
SubjectPipeline of the day — {ROWS} lines computed
BodyThe daily pipeline is ready. Open the CRM dashboard for the detail.

The placeholders of a job event are JOB, RUN_ID, STATE, ERROR, DURATION_MINUTES and ROWS. Send a test sends the rule with sample values. See Notifications → Rules.

5. The detail​

A dashboard widget or a screen on daily_pipeline (for example a bar chart by stage, filtered on the last report_date), reachable from the menu. See Dashboards.

6. When it fails​

The job's own alerts e-mail the operators on failure — see Notifications → A job's own alerts.

When a file must be attached​

A job sends a file itself with two steps — no code:

  1. a report step renders a shared analysis or dashboard of the Data Explorer to Excel or PDF, over a period preset (Last month), and as a given user when the recipients must only see their own scope;
  2. a notify step sends the message to role:management, with Attach set to *: every file the run produced goes with the e-mail.

The notification rule on the job's success is then no longer needed. See Steps → Report and Steps → Notify.

Variations​

NeedHow
Weekly, on MondaysCron 0 8 * * 0.
A message in Teams or another toolA notification rule with the action channel, calling an API connector endpoint (a webhook).
A warning only when something is wrongA step that fails when a check is not met, and a rule on the failure event.

What's next​