Dynamically populate select from DB

Hello Experts,
We have a sales order, there is link field for Territory linked to territory doc.
And also, there is the customer link filed linked to customer doc.
I want to populate only those customers which match the territory selection.

Please give me an example for this.

Regards.

Hi @Narayan_Banik:

As far I know, Territory is shown after customer selection … So, first of all, you need to customize Sales Order docytpe and remove related “Address & Contact” tab property:

image

Then, create a client script for Sales Order doctype (and enable it)

frappe.ui.form.on('Sales Order', {
	territory(frm) {
	    frm.set_query('customer', function() {
			return {
				filters: {
					'territory': frm.doc.territory
				}
			};
		});
	}
})

Hope this helps.

Thanks…I just give an example in the question. Here is my below code:

In Case form,
I want to apply filter on assigne link field based on vendor choosing …

Below function trigger when vendor changes…

But I dont get reflection that filter applies on assignee field.

frappe.ui.form.on('case', {
        vendor(frm) {
            console.log(frm)
            frm.set_query('assigne', function() {
                        return {
                                filters: {
                                        'vendor': frm.doc.vendor
                                }
                        };
                });
        }
})

Regards.

It worked…There was a typo…should be assignee instead of assigne