Cascading /Nested Add Fetch

Issue : Want to fetch Sales Person Email id.

Doctype : Sales Person has field Employee
Doctype : Employee has field prefered_email

Now in Sales Order, i have added custom field “Sales Person”, now based on Sales Person selection , would like to fetch employee and from employee would like to retrieve prefered_email.

Sales Person – > Employee → prefered_email

Is it possible (have you tried) to do two/second level add fetch, if yes please provide custom client script ?

No need for custom script for the first two fields. Now, as you know each Sales Person has employee mentioned in it.

Assuming your fields are named sales_person, employee, prefered_email:

In Customize Form, as you have mentioned Sales Person in Options of sales_person, similarly mention sales_person.employee in Options of employee so the linked employee will be auto-filled.

For the prefered_email you may have to use a custom script. But still try if something like sales_person.employee.prefered_email works or not. I think it should because Employee mentioned in Sales Person too is a linked document.

Thanks for the idea, but it didn’t worked i tried below settings.

For Employee if the field type is Link , Option column should have the linked doctype name , so below is not possible

Ah yes if it is link this won’t work. Then you ought to use custom script.

@jignesh_shah try below script to fetch employee id from Sales Person & for prefered_email set option as employee.prefered_email

Note : Set employee’s field type as a Link.

frappe.ui.form.on("Doctype", "sales_person", function(frm) {{
        "method": "frappe.client.get",
        "args": {
             "doctype": "Sales Person",
             "name": frm.doc.sales_person
        "callback": function(response) {
             var sales_person = response.message;
             if (sales_person) {
                  frm.set_value('employee', sales_person.employee);
             } else {
                  frappe.msgprint("Sales Person not found");

Thanks for your hep.

Sorry it didn’t worked. On Selection of Sales person , Employee and Email id are not fetched.

After selecting Employee , prefered_email is fetched , which is because of employee.prefered_email in the Option

Tried as below

Custom Client script as suggested by you.


What version of Frappe and ERPNext are you on?

In the DocType expand the Employee field and see if there’s an input for fetch_from? If so, then write the sales_person.employee in fetch_from and not in options.

ERPNext: v10.1.52 (master)

Frappe Framework: v10.1.47 (master)

fetch_from not available .

try this i write for user_id field you can change whatever field you want to fetch.

frappe.ui.form.on("Sales Order", "sales_person",function(frm,cdt, cdn) 
				"method": "frappe.client.get",
				args: {
					doctype: "Sales Person",
					name: frm.doc.sales_person
				callback: function (data) {
				"method": "frappe.client.get",
				args: {
					doctype: "Employee",
				callback: function (data) {
					frm.set_value("p_email", data.message.user_id);





Thanks All. it is working.

can set the values for the desired fields as below

frm.set_value(“employee”, data.message.employee);
frm.set_value(“prefered_email”, data.message.prefered_email);