Thank you. This is exactly what I am looking to do. Extend the onload event of the Sales Invoice listview. However for some reason its still not firing!
I used the code from @snv and just changed the document name to Sales Invoice. That is the only change I made - so code is:
function extend_listview_event(doctype, event, callback) {
if (!frappe.listview_settings[doctype]) {
frappe.listview_settings[doctype] = {};
}
const old_event = frappe.listview_settings[doctype][event];
frappe.listview_settings[doctype][event] = function (listview) {
if (old_event) {
old_event(listview);
}
callback(listview);
}
}
extend_listview_event("Sales Invoice", "onload", function (listview) {
console.log ('Sales invoice onload event') //still doesn't fire :-(
});
Thanks all, really appreciate all the help on this. I am learning some things and hopefully we are creating some clarity for anyone who reads this thread
I copied and pasted my code into the script editor as per the video, and yes it does work The difference is that I am not using the script editor, rather I am using my own javascript file that I link up in hooks.py. I.e. in hooks.py I have app_include_js = "/assets/erp/js/erp.js" (my custom app is just called “erp” at the moment) and then I have the code in erp.js. This is where it doesn’t fire, so there must be a suble difference between the way custom scripts you save in the UI work, and the same javascript in regular code.
I can probably use a UI based custom script as a work-around although it won’t be a neat solution. For comepleteness it would be nice to know if the Sales Invoice list can be customised using app-wide script, even if its over-riding not extending