Extending the List-View Client Script for ERPnext DocTypes

Gentlemen,

I wanted to add a button to the List-View of “Payment Entry”. This seemingly simple endeavour took a surprising turn, maybe some of you know of a better solution than the one I applied.

I went to “Build > Client Script” and created “Payment Entry-List” with this Code:

    frappe.listview_settings['Payment Entry'] = {
        onload(listview) {
            listview.page.add_inner_button(__("Hello"), () => msgprint("Hello"));
        },
    };

Woe to me! My code overwrote the onload-event already defined in erpnext/erpnext/accounts/doctype/payment_entry/payment_entry_list.js.

I came up with this solution that works pretty well:

// Get the already defined instance
let holder = frappe.listview_settings['Payment Entry'] || [];
// Remember the already defined onload-event
let onload_overridden = holder.onload;

// Add own functionality and also call original functionality
holder.onload = function(listview) {
    onload_overridden(listview);
    listview.page.add_inner_button(__("Hello"), () => msgprint("Hello"));
};

Is there a better way to do it?

I realized when you are working with Form-Views such hardship is not necessary.
frappe.ui.form.on(‘Name of DocType’, { … }) handles Client Script stored in the filesystem and the DB in a way that calls both scripts after each other.

Is there something like this for List-Views?

3 Likes

I’m also interested in this… I’ve encountered issues trying to get listview scripts to work as expected

1 Like