List view custom script to add action to "Actions" menu

V13. I couldn’t find the answer in the documentation, sorry.

I’m trying to add a new action to the “Actions” menu in the “Sales Invoice” list view. I want this action to iterate through all the selected sales invoices and perform a custom action on each of them. However, I am falling at the first hurdle as I cannot figure out how to add the item to the menu.

All the examples I can find of custom scripts are for forms and these have been very useful for the other custom scripts I’ve been developing but I cannot find examples of custom scripts for the list view.

Hi @BillJ,

Please check this topic.
Maybe, it will help you.

Thank You!

Thanks, @NCP!
I have successfully added the action menu option using the custom client script:

frappe.listview_settings['Sales Invoice'].refresh = function(listview) {
    // add button in menu
    listview.page.add_action_item(__("Test option"), function() {
    	test( listview );
});
};

function test( listview )
{
    frappe.msgprint("Test passed");
}

Now all I need to figure out is how to iterate through all the selected sales invoices so I can operate on each in turn.

1 Like

One problem I did find with the code above is that when the list view loads, the “Actions” button appears even though there are not yet any documents selected. If I hook into the “onload” event instead of the “refresh” event, then the “Actions” button does not appear until I select a document, as normal.

frappe.listview_settings['Sales Invoice'].onload = function(listview) {
    // add button in menu
    listview.page.add_action_item(__("Test option"), function() {
    	test( listview );
});
};

function test( listview )
{
    frappe.msgprint("Test passed");
}