Frappe.listview_settings not working

I cannot figure out what’s wrong in this script, (adding through custom script of Sales Invoice)

frappe.listview_settings[‘Sales Invoice’] = {
filters:[[“is_pos”,“=”, “No”]]
};

Still only shows “!cancelled” filter, but not is_pos filter…?

1 Like

Custom Script can only be used for forms and not listviews.

3 Likes

@netchampfaris
Hi Faris. Thanks for answer. I didn’t notice that!

So now, I know we can add js in to custom app hooks but this will be sales_invoice_list.js

Will this work?
In hooks.py

doctype_list_js = {
“Sales Invoice”:“sales_invoice_list.js”,
}

And In sales_invoice_list.js

frappe.listview_settings[‘Sales Invoice’] = {
filters:[[“is_pos”,“=”, “No”]]
};

Please explain. Thanks.

2 Likes

Your solution should work.

Make sure the file path is correct

Hi @akashpvtltd
I also tried your code but didn’t work, even path was correct.

I solved it by using this:

frappe.listview_settings['Sales Invoice'] = {
onload: function(listview) {
	if (!frappe.route_options){
		frappe.route_options = {
			"City": ["=", "city1"]
		};
	}
}};

Although I am trying to get how get filter from other Logged User Doctype’s field.
Here is a link:

Hi @mdwala
I have a similar problem and I have found variants of your snippet in many forum threads. My problem is that the filter doesn’t get updated after the code is run. I’m making sure the code is run with a frappe.msgprint(), do I need to do anything to apply the filter after it is set?

frappe.listview_settings['QR Code'] = {

    //Add scan QR button and filter scanned qr code
    onload(listview) {
        
        // triggers once before the list is loaded
        listview.page.set_secondary_action('Scan QR', () => {
            console.log("Scan QR Pressed");
            new frappe.ui.Scanner({
              dialog: true, // open camera scanner in a dialog
              multiple: false, // stop after scanning one value
              on_scan(data) {
                //Set filter for scanned QR Code
                if (!frappe.route_options){ //remove this condition if not required
        			frappe.route_options = {
        				"serialnumber": ["=", data.decodedText]
        			};
        			frappe.msgprint({
                    title: __('Notification'),
                    indicator: 'green',
                    message: __(data.decodedText)
                    });
		        }
                
                }
            });
        });
  }
    
};

I’ve also tried hard coding the value in the filter but nothing happens?
The filter works as expected when I manually set the filter on the same field.

its worked on erpnext what version?