How to fetch employee based on field

in the employee i have create one select field ‘channel partner type’



and in the lead i have create same field ‘channel partner type’

now i want in the lead doctype when i select channel partner type as ‘individual’ then in the ‘Channel Partner Name’ field shows those employee whose channel partner type is individual and ‘Channel Partner Name’ field is link to employee doctype

Hello @Rahul7218

According to your requirements.

You create a field in Lead Doctype
fieldname “Employee”
fieldtype “Link” (Linked with Employee doctype")
Options “Employee”

then add client script on Lead Doctype for filter on the employee field on the base of Channel Partner Type selection.

frappe.ui.form.on('Lead', {
	channel_partner_type(frm) {
		frm.set_query("employee", function() {
			return {
				filters: {
					"channel_partner_type":frm.doc.channel_partner_type
				}
			};
		});
        }
});

@Usama_Naveed Not working

Have you modified the code according to your fieldnames?

Yes
But not working

image
this field is in both doctype employee and lead

now in employee doctype i have 2 employee whose channel partner type is individual


now i want in the lead if i select channel partner type is ‘individual’

then in the ‘channel partner name’ field which is link to employee doctype show me those 2 employees only whose channel partner type is individual

Share the your updated code

and tell the fieldname of “Channel Partner Type” Field

Ok let me share

@Usama_Naveed

frappe.ui.form.on(‘Lead’, {
custom_channel_partner_type(frm) {
frm.set_query(“employee”, function() {
return {
filters: {
“custom_channel_partner_type”:frm.doc.custom_channel_partner_type
}
};
});
}
});

this employee fieldname exist in the Lead doctype?

ohh
i have change the code
and its working
frappe.ui.form.on(‘Lead’, {
custom_channel_partner_type(frm) {
frm.set_query(“custom_channel_partner_name”, function() {
return {
filters: {
“custom_channel_partner_type”:frm.doc.custom_channel_partner_type
}
};
});
}
});

Thank you @Usama_Naveed

1 Like