Skip to content

Reviewer Configuration En

Task Reviewer Configuration

In ERPNext there is Notification settings where you can configure alarms on different actions. But let’s say you need to create the notification of assigning a reviewer to some task.

For instance you created a Reviewer field in the Task doctype. The Reviewer field is link on the Employee doctype. So you can pick a reviewer for a task and you want the reviewer to be notificated about this event.

So we need to modify Notification doctype to be able to send notifications to a reviewer of a task.

Send To The Reviewer Python Logic

  1. Go to the Task doctype and click on the “Customize” button

  2. Add the Reviewer field and specify the Link type, in the Options form write “Employee”

  3. Go to the Notification doctype and click on the “Customize” button

  4. After send_to_all_assignees field add a new field; label it “Send To The Reviewer”, name it send_to_reviewer and select the Check type

  5. Go to the “Recipients” field, in the “Mandatory Depends On” form, in the end of the first line add the && !doc.send_to_reviewer code so the whole text looks like this:

    eval:doc.channel!=='Slack' && !doc.send_to_all_assignees && !doc.send_to_reviewer

    After this configuration the “Recipients” field will not be mandatory if the send_to_reviewer option is enabled

  6. Go to the following path in the file system of Frappe Framework:

    /workspace/development/frappe-bench/apps/frappe/frappe/email/doctype/notification/notification.py

  7. In the end of the notification.py file we’ll write the get_task_reviewer function that gets a reviewer of a task

    def get_task_reviewer(doc):
    reviewer = frappe.db.get_value("Task", doc.name, "reviewer")
    if reviewer:
    reviewer_email = frappe.db.get_value("Employee", reviewer, "user_id")
    if reviewer_email:
    return reviewer_email
    • Using def we define the get_task_reviewer function that takes the doc parameter
    • We create the reviewer variable and get a value from the reviewer field of the “Task” doctype using frappe.db.get_value (doc.name tag gets the name of the current document, in our case it gets the task name from which the notification will be sent)
    • If the reviewer value is true then we declare the reviewer_email variable, it contains the email of the reviewer which is collected using frappe.db.get_value and the reviewer’s name
    • If the reviewer_email value is true the function returns it
  8. In the notification.py in the get_list_of_recipients method find following lines:

    if self.send_to_all_assignees:
    recipients = recipients + get_assignees(doc)
  9. We shold type the following code of the send_to_reviewer option after the lines above

    # For Send To the Reviewer custom field
    if self.send_to_reviewer:
    if validate_email_address(get_task_reviewer(doc)):
    recipients.append(get_task_reviewer(doc))
    • In the code above by first step we check if send_to_reviewer field of a Notification obejct is True (or turned on)
    • We check if the value that the get_task_reviewer function returned is true and if it is this value appends to the end of the recipients list

Send To Reviewer JavaScript Logic

Now when we have the logic of the send_to_reviewer option let’s create the client script that would show the Send To The Reviewer option if the Task doctype specified in the Document Type field of the Notification settings

  1. Go to the “Client Script” doctype

  2. Press the “Add Client Script” button

  3. Name your client script and select the “Task” doctype in the “DocType” field

  4. Write the following script in the “Script” form

    function reviewer_hide(frm) {
    if (frm.doc.document_type === 'Task') {
    frm.set_df_property('send_to_reviewer', 'hidden', 0);
    } else {
    frm.set_df_property('send_to_reviewer', 'hidden', 1);
    frm.set_value('send_to_reviewer', 0);
    }
    }
    frappe.ui.form.on('Notification', {
    document_type(frm) {
    reviewer_hide(frm);
    },
    onload(frm) {
    reviewer_hide(frm);
    }
    })
    • First we create the reviewer_hide function that takes the frm parameter
    • If the document_type value is Task then we change the hidden property of the send_to_reviewer to 0 using the frm.set_df_property function; otherwise we change the hidden property to 1
    • We use the frappe.ui.form.on to use the reviewer_hide function in the Notification doctype
    • The document_type(frm) is used to perform the reviewer_hide function when the document_type field has changed
    • The onload(frm) is used to perform the reviewer_hide function when a page is load

Using the “Send To The Reviewer” option

Now then we have the Send To The Reviewer option we can use it in different types of notification. Fot enstance we want the reviewer to get the notification of task status changing.

We can create such notification using the Send To The Reviewer option

  1. Go to the Notification doctype and press the Add Notification button

  2. Name the notification

  3. Write the subject of the notification

  4. In the Send Aler On pick the Value Change option

  5. In the Value Changed pick the status (Status) option

  6. Pick the sender (Configured Email Account)

  7. In the Document Type doctype pick the Task option

  8. Turn on the Send System Notification option

  9. In the Recipients form turn on the Send To The Reviewer option

  10. In the Message form type the message which the notification will contain

  11. Press the Save button