ERPNext Corepython

ERPNext Notification Control (Alerts)

Notification Control

A complete guide to staying informed about important business events in ERPNext using automatic email, SMS, and Slack notifications.

Staying on top of critical business events is essential for smooth operations. ERPNext's Notification Control (formerly known as Email Alerts) allows you to automate communication based on document changes.

Whether it's notifying a sales manager about a high-value order, alerting the warehouse team of a new delivery, or sending payment reminders to customers, Notification Control handles it all automatically.

1# Example: High Value Order Alert
2# Trigger: On Submit of Sales Order
3# Condition: Grand Total > 10000
4
5subject: High Value Order: {{ doc.name }}
6recipients:
7 - role: Sales Manager
8 - email: ceo@example.com
9
10message: |
11 A new high-value order has been submitted.
12 Customer: {{ doc.customer_name }}
13 Amount: {{ doc.grand_total }}
14

Understanding This Code

What It Does

Automatically sends emails, SMS, or Slack messages when specific events occur in the system (like creating, saving, or submitting a document).

When To Use

Use alerts to keep stakeholders informed about critical updates without manual intervention, such as approval requests, high-value transactions, or stock level warnings.

Prerequisites

  • System Manager role to configure.
  • Configured Email Account for sending emails.
  • Slack/SMS settings configured if using those channels.

Key Concepts

Important ideas to understand in this code

Triggers

Events that start the notification process. Common triggers include 'New' (document creation), 'Submit' (document finalization), 'Cancel', 'Save', or 'Value Change' (critical for security monitoring).

Learn more

Conditions

Logic checks to determine if the alert should be sent. You can use simple field comparisons or complex Python/JavaScript expressions to target specific scenarios (e.g., Grand Total > 10000).

Learn more

Recipients

Who receives the message? Recipients can be dynamic (document owner, customer contact), fixed email addresses, or specific system Roles (e.g., Accounts Manager).

Step-by-Step Tutorial

Follow along to understand how this code works

1

Access Notification List

Navigate to the Notification list to manage your alerts. You can find this by searching for 'Notification' in the awesome bar.

text
Search: Notification List
Next Step
2

Create New Notification

Click 'Add Notification'. Enter a descriptive Subject. In the 'Document Type' field, select the document you want to monitor (e.g., Sales Order, Leave Application).

yaml
Subject: High Value Order Alert
Document Type: Sales Order
Next Step
3

Set Trigger and Conditions

Choose when the alert sends (e.g., on 'Submit'). Add a condition if needed. For example, to alert only for orders above $5,000:

python
Send Alert On: Submit
Condition: doc.grand_total > 5000
Next Step
4

Configure Recipients

Define who gets the message. You can send to specific email fields (like `contact_email`) or to internal users by Role. You can also send to fixed email addresses.

yaml
Send To: Sales Manager (Role)
CC: ceo@example.com (Fixed)
Next Step
5

Design the Message

Draft your message content. You can use Jinja templating to include dynamic data from the document, such as the Customer Name or Grand Total.

jinja2
Hello,

A new high-value order {{ doc.name }} from {{ doc.customer_name }} amounting to {{ doc.grand_total }} has been submitted.

Regards,
ERP System

Beyond operational updates, Notifications are a powerful tool for Security and Audit trails. You can monitor sensitive changes in the system to ensure compliance and prevent unauthorized access.

Step-by-Step Tutorial

Follow along to understand how this code works

1

Monitor Sensitive Fields

Want to know if someone changes a User's Role Profile? Set a notification on the 'User' document triggered by 'Value Change' on the 'role_profile_name' field.

yaml
Document Type: User
Send Alert On: Value Change
Value Changed: role_profile_name
Next Step
2

Alert on Permission Changes

Receive an immediate email if a 'Role Permission Manager' document is modified or deleted. This is crucial for maintaining system integrity.

yaml
Document Type: Custom DocPerm
Send Alert On: Save
Next Step
3

Restricted Access Attempts

While you can't alert on 'view' attempts easily, you can alert if a user tries to 'Cancel' a key document. This serves as a warning for potentially destructive actions.

python
Document Type: Purchase Order
Send Alert On: Cancel
Condition: doc.status == 'Compromised'

Common Issues & Solutions

Troubleshoot problems you might encounter

Finbyz Tech | ERP, AI, Software, and Dedicated Talent - All in One Partner