Try ERPNext Buy Support Partners Foundation

Alternative to cscript not working

I’m trying to filter Items by Item Group in Sales Invoice. The only solution that seems to work consistently for me is the depreciated cur_frm.cscript…

I wanted to make it work using this code:

frappe.ui.form.on('Sales Invoice', {
    refresh : function(frm, cdt, cdn) {
    	frm.set_query("item_code", "items", function() {
    		return {
    			filters: {"item_group": "Products"}
    		}
    	});
    }
});

also onload instead of refresh doesn’t work.

But this depreciated code works without any problems:

cur_frm.cscript.onload = function(frm) {
	cur_frm.set_query("item_code", "items", function() {
		return {
			filters: {"item_group": "Products"}
		}
	});
}

Any reason why this is? And how to make the non depreciated snippet work?

In the deprecated version, you used the onload event, why not try the same in the new one:

frappe.ui.form.on('Sales Invoice', {
    onload: function(frm) {
    	frm.set_query("item_code", "items", function() {
    		return {
    			filters: {"item_group": "Products"}
    		}
    	});
    }
});

I have written in the first post that I tried onload instead of refresh but it didn’t work.
I have reloaded/emptied cache after every change.