Add Button in Menu in List View of Customer

Hi,

I am currently trying to add a button in menu in the list view of customer. My problem is that I cannot see that button in customer list view. But if I change my doctype in code to “Lead” instead of “Customer” (or something else) it’s showing in list view of lead!

Here’s my code:

frappe.listview_settings[‘Customer’] = {
refresh:function(listview) {
listview.page.add_menu_item(__(“button_name”), function() {
frappe.call({
method: “path_to_method”,
args: {}
});
});
}
}

Has anybody a solution for me?

For anybody with the same problem, i solved it! Instead of adding the script in my repository, I added a client script in ERPNext and checked “Is active”. This did the job.

I had posted about the issue that some js works in custom app’s doctype files and some only works in client script.
Is there any docs or explanation which can be in custom app and which should be in client script?

@rahy I didn’t find any docs for this topic. But I figured out why the script didn’t work in my repository! ERPNext has a file named “customer_list.js” with following code:


When I comment this code out, my script is working. I assume that it’s not possible to have 2 scripts with listview_settings for Customer. Maybe it’s the same problem with other files and processes.

Refer to the sample JavaScript script below. Additionally, make sure that the JavaScript file is properly referenced in your hooks.py file if it is not located in the public folder.

The example below demonstrates how to add a new button. Note that this button will appear under the “ACTIONS” dropdown menu when a record is selected.

JS File is located in folder:

myapp/js/myscript.js

JS Script:

frappe.listview_settings['Item'] = {
    onload(listview) {
         console.log("✅ Custom Script Inline JS Loaded");

        listview.page.add_actions_menu_item(__('Print Price Labels'), async () => {
            alert("clicked from script");
        });
    }
};

JS Reference entry in the hook.py file:

doctype_list_js = {
    "Item": "js/item.js",
}

Here is the Result:

Hope this will helps.