Create a notification ​

A notification sends a message when something happens to a document. For example:

  • Remind the project manager when a Task passes its expected end date.
  • Tell the sales manager when a Sales Order above a set value is submitted.
  • Remind a customer of a payment three days before the due date.
  • Warn the legal team 30 days before a Contract expires.

This page sets up an email notification. To send it to Slack, as an SMS, or to the notification bell instead, read Choose a notification channel.

Prerequisites ​

  • The System Manager role.
  • An outgoing email account for email notifications.

Create the notification ​

  1. Open the Notification list, and select New.
  2. Keep Channel as Email.
  3. In Document Type, select the document to watch, for example Task.
  4. In Send Alert On, select the event. The events are described below.
  5. Optional: enter a Condition. The notification goes out only when the condition is true.
  6. In the Recipients table, add the recipients.
  7. Enter the Subject and the Message.
  8. Select Save.

Events ​

Send Alert OnWhen ERPNext sends the notification
NewA document of this type is created.
Save, Submit, CancelA document is saved, submitted, or cancelled.
Days Before, Days AfterA number of days before or after a date in the document. Select the date field in Reference Date, and enter Days Before or After. ERPNext checks once a day.
Minutes Before, Minutes AfterA number of minutes before or after a date and time in the document. Select Reference Datetime, and enter the Minutes Offset.
Value ChangeThe value of a field changes. Select the field in Value Changed.
MethodA controller method runs, for example before_insert. Enter it in Trigger Method.
CustomNot on a document event. An app or a script sends it.

INFO

From version 16, you can select a child table as the Document Type when Send Alert On is Days Before or Days After.

Recipients ​

Each row of the Recipients table adds recipients in one of these ways:

  • Receiver By Document Field: a field of the document that holds an email address or a user, for example the Owner or the Contact Email.
  • Receiver By Role: all users with a role, for example Sales Manager.
  • CC and BCC: fixed email addresses.

A row can have its own Condition.

To email every user who is assigned to the document, select Send To All Assignees.

Write the condition ​

A condition is a Python expression. Write a field as doc.<field name>. For example, to send the notification only for Leads with the status "Interested":

python
doc.status == "Interested"

Combine conditions with and and or:

python
doc.status == "Open" and doc.exp_end_date <= frappe.utils.nowdate()

To find a field name, open Customize Form, select the DocType, and read the Name column. You can also set Condition Type to Filters, and build the condition with filters instead of Python.

Write the subject and message ​

The subject and message use Jinja tags. Write a field in double braces, as doc.<field name>. For example, the subject {{ doc.name }} has been created gives "TASK-0001 has been created".

The message can contain HTML:

jinja
<h3>Order Overdue</h3>

<p>Transaction {{ doc.name }} has exceeded its due date. Please take action.</p>

{% if comments %}
Last comment: {{ comments[-1].comment }} by {{ comments[-1].by }}
{% endif %}

<ul>
  <li>Customer: {{ doc.customer }}</li>
  <li>Amount: {{ doc.grand_total }}</li>
</ul>

To add a link that opens the document, put this in the message:

jinja
<a href="{{ frappe.utils.get_url_to_form(doc.doctype, doc.name) }}">{{ doc.name }}</a>

Attach the document ​

Select Attach Print, and select the Print Format. ERPNext attaches the PDF of the document. To attach files, set Attach Files to All, or to From Field and select the field.

Send a notification only once ​

A condition can be true many times, for example on every save. To send the notification only once:

  1. Add a check field to the document, for example Notification Sent, in Customize Form.
  2. In the notification, set Set Property After Alert to that field, and Value To Be Set to 1.
  3. Add the field to the condition: doc.notification_sent == 0.