How to email delivery note to transporter upon submit via Notification?

I am trying to send the delivery note by email Notification to the transporter (supplier). Under notification, I see the option to send email by Role (to supplier). Will that send email to all suppliers? Or Supplier associated with that document?

I thought of creating a custom field in delivery note called supplier_email. how to link it to the supplier contact (fetch email address of supplier)?

Appreciate any guidance. Thanks.

All suppliers. If you send a notification role-wise, all users having the role will be updated. The option is to create a field and enter “Email” in option. This will allow you to select the email field in notification.

The easiest way to do this:

  1. Create custom link field for contact doctype.
  2. Create custom field type: data, option: Email.
  3. For the email field, fetch the email address from contact.

If you want additionally to only select a supplier and based on that the rest of the process to be automated, you can look at custom script options.

@kennethsequeira - Thank you for taking the time to respond.

Doctype Contact seems already has a data field for email_id. In delivery note, customer contact_email is populated automatically - so I am assuming I do not need to recreate a link field? On a side note, wondering how contact_email in delivery note automatically links to email address of customer contact.

Per your instructions (I think!) , I created a custom field for Delivery Note called transporter_email. It is of type Data with Options as Email. Under fetch I tried supplier.contact.email_id, and transporter.contact.email_id. None of them work - so will appreciate clarity on how to fetch ins Step 3? Transporter is named in Delivery Note from dropdown (line 96 of form). I have added custom field after this row (line 103 in std doctype). Does that make sense?

Many thanks for your time and courtesy.

Big shout out to @hrwx for contributing this script. Sincere thanks on behalf of the community. Script dynamically filters doctype contacts for supplier and then for the transporter and return the primary contact default email_id field. It can be applied for other situations where you need to pull a field (in this case email_id) from one doctype (contact / supplier) to another doctype (delivery note) with dynamic filters (based upon a user selection - in this case transporter as a subset of suppliers).

Small explanation for future reference:
The first step is to create a custom field in Delivery Note called transporter_email, with options as Email. Then need to add this custom script for document type Delivery Note. This transporter_email will now be available as an option under email Notification - so delivery note can be sent to transporter upon submit.

Custom Script:

frappe.ui.form.on("Delivery Note", {
	transporter: function(frm) {
		if (!frm.doc.transporter) {
			return;
		}
		frappe.call({
			'method': 'frappe.client.get_list',
	      		'args': {
            			'doctype': 'Contact',
            			'filters': [
					["Dynamic Link", "parenttype", "=", "Contact"], 
                			["Dynamic Link", "link_doctype", "=", "Supplier"], 
					["Dynamic Link", "link_name", "=", frm.doc.transporter], 
            			],
	           		'fields':'email_id'
        		},
        		'callback': function(r){
				if (r && r.message) {
					frm.set_value("transporter_email", r.message[0].email_id);
					refresh_field("transporter_email");
				}
        		}
    		});
	}
})
4 Likes