How to refresh field

Hello,
I have created a Maintenance DocType. I made a custom script for filtering machines from their Category.
I need Machines field to be refreshed based on the Category field .
In the below first image I have selected Machines from 3PL Machinery.
If I change the Category , the machine remains the same.
Thank you


when I change the category field it remains the same

frappe.ui.form.on("Maintenance",{
    refresh: function(frm){
		frm.set_query("category", function(){
			return {
				"filters": [
					["MList", "check", "=", "1"]
				]
			};
		});
	}
});

frappe.ui.form.on("Maintenance",{
    refresh: function(frm)
    {
       
		frm.set_query("machine", function(){
			return {
				"filters": [
				["MList", "category", "=", frm.doc.category, ],
				]
			};
		});
	}
});


@Dharanipathi You can achieve what you want by using the following code.

frappe.ui.form.on("Maintenance",{
    refresh: function(frm){
		// Your code
		frm.set_query("category", function(){
			return {
				"filters": [
					["MList", "check", "=", "1"]
				]
			};
		});
		frm.set_query("machine", function(){
			return {
				"filters": [
				    ["MList", "category", "=", frm.doc.category, ],
				]
			};
		});
	},
	category: function(frm) {
		// New code
	    if (frm.doc.category) {
	        frm.refresh_field('machine');
	    } else {
	        frm.set_value('machine', '');
	    }
	}
});

This code will clear the machine field if the category field is empty and will refresh it if not.

1 Like