Adding "Report Issue" Button to Form and List View Globally in Frappe


Hello Frappe Community,

I’m working on a custom app named “Issue Tracker” to add a “Report Issue” button globally to both form and list views for all doctypes. I successfully added the button to the Item doctype, but I encountered issues when trying to apply it globally.

Code for Form View:

frappe.ui.form.on('Form', {
    refresh: function(frm) {
        frm.page.add_menu_item(__('Report Issue'), function() {
            frappe.msgprint(__('Report Issue button clicked in Form View'));
        });
    }
});

Code for List View:

frappe.views.ListView.prototype.add_menu_item = function(label, action) {
    this.page.add_menu_item(label, action);
};

const original_refresh = frappe.views.ListView.prototype.refresh;
frappe.views.ListView.prototype.refresh = function() {
    original_refresh.call(this);
    this.add_menu_item(__('Report Issue'), function() {
        frappe.msgprint(__('Report Issue button clicked in List View'));
    });
};

Inclusion in hooks.py:

app_include_js = [
    "/assets/issue_tracker/js/global_form_script.js",
    "/assets/issue_tracker/js/global_listview_script.js"
]

I have tried clearing the cache and rebuilding the assets, but the buttons are not appearing globally. Any guidance or suggestions to resolve this issue would be greatly appreciated!

Thank you!


@Omar_Mohammed
@Ashish_Soner