Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

Filter second field options based on first field selection


I have created 3 doctypes, 1. Country doctype, 2. City doctype 3. doctype3

Country doctype will have all the country names, City doctype will have all the cities with its respective Country link from Country doctype.

In 3rd Doctype i have created two fields with links to Country and City doctypes.

so what i want is if i select country, the city field should show only cities which are related to a specific country.

right now city field showing all cities from all countries.

Should we have to write custom script? or is there any option to select in 3rd doctype?

You would have to write a custom script using frm.set_query.

Refer documentation:

frappe.ui.form.on("Doctype3", {
	linkfield: function(frm) {
		frm.set_query("linkfield", function() {
			return {
				filters: [
					["country_doctype","country", "in", [frm.doc.country_doctype_field]]

linkfield is the fieldname of the city field
country_doctype_field is the name of the field linking to Country Doctype
country is the country link fieldname in the City Doctype

Try this and let me know.