Need filter for child name based on feild

Dear Community.
customer doctype i had two fields

1.City as custom_city (Link)
2.Area as custom_area (link)

Here city is under doctype name Province under this doctype city names are created

For Area i create one doctype name Area under the doctype i linked with city and
each cities may have more than 3 area so created one table in name of Area Name

for eg:
In Area doctype.
there is two field City as link (city) and Area Name as table (area_name)

if City as Basra.
Area Name in Table as Al Faw,Al Medina,Al Qurna etc

so in customer doctype if i select city as Basra in area field should only show area names as Al Faw,Al Medina,Al Qurna not city names.

image

but in customer doctype Area only show link how to make filter on Table.

Learn this.

2 Likes

frappe.ui.form.on(“Customer”, “onload”, function(frm){
frm.set_query(“customer_area_table”, function(){
return {
“filters”: [
[“Customer Area Table”,“=”, “Area Name”],
]
}
});
});

this is need some thing add?

Please check the all example, lots of posts there in the forum so search them.

Even i apply this is not working.
frappe.ui.form.on(‘Customer’, {
custom_city: function(frm) {
frm.set_value(‘customer_area_table’, ); // Clear existing rows
frm.trigger(‘load_area_names’); // Reload areas based on selected city
},

load_area_names: function(frm) {
    if (frm.doc.custom_city) {
        // Fetch areas based on the selected city
        frappe.call({
            method: 'frappe.client.get_list',
            args: {
                doctype: 'Area',
                fields: ['area_name'],
                filters: {
                    'city': frm.doc.custom_city
                }
            },
            callback: function(r) {
                if (r.message) {
                    // Add fetched areas to the child table
                    r.message.forEach(function(area) {
                        frm.add_child('customer_area_table', {
                            'area_name': area.area_name,
                            'city': frm.doc.custom_city
                        });
                    });
                    frm.refresh_field('customer_area_table');
                }
            }
        });
    }
}

});

please guide me to solve this issue

Please check the video and script.

Client Script:

frappe.ui.form.on("Test DocType", {
    state: function(frm) {
        if (frm.doc.state) {
            frappe.call({
                method: 'frappe.client.get',
                args: {
                    doctype: 'State',
                    name: frm.doc.state
                },
                callback: function(r) {
                    if (r.message) {
                        var options = r.message.states_city.map(function(city) {
                            return city.city;
                        });
                        frm.set_df_property('city', 'options', options.join('\n'));
                        frm.refresh_field('city');
                    }
                }
            });
        } else {
            frm.set_df_property('city', 'options', '');
            frm.refresh_field('city');
        }
    }
});

Now set your according to the scenario.

2 Likes

Thanks for your help

Dear NCP,
The above two fields Area and city added in Address Doctype but in HTML it only take standard field as default any way to add this field in html.

image

Thanks in Advance

Please explore this.

1 Like

Thanks for giving this solution sir