Try ERPNext Buy Support Partners Foundation

Adding Button in Menu under List View

Trying to add button under Menu dropdown in a Doctype
Tried writing code [doctype_list.js] in Custom App within folder of standard Doctype [Serial No] but the code does not get triggered and no button is added.
Used this as reference

Writing code in the core JS file might break during the update.

Has anyone done this before? Any pointer in right direction?

Thanks

I understand you want to add a custom script to Serial No DocType.

In your custom app (my_app), save your code in the folder my_app/public/js/. For example, my_app/public/js/serial_no.js. The content of this file is your custom script. It would look something like this:

frappe.ui.form.on("Serial No", "refresh", function(frm) {
    frm.add_custom_button(__("Do Something"), function() {
            console.log("Did something");
        });
    });
});

Then go ahead and tell frappe to serve this file with the Serial No DocType: open your app’s hooks (my_app/hooks.py) and add your script to the doctype_js or doctype_list_js variables.

# ...
doctype_js = {"Serial No" : "public/js/serial_no.js"}
# ...
3 Likes

Thanks I was missing the hooks.py step.
Thanks for your help.

You’re welcome! Please mark my answer as solution, if it solved your problem :slight_smile:

I tried, for some reason, I don’t see the option to mark it as a solution. Don’t know why

Weird, usually it should look like this:

01

Yup it is weird, don’t see that option