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

1 Like

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"}
# ...
6 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

the menu already changed as action menu, my working code is as below

frappe.listview_settings[‘Demand Estimate’] = {

onload: function(listview) {

    listview.page.add_actions_menu_item(__("Create Components Demand Estimate"), function() {

        const docnames = listview.get_checked_items(true).map(docname => docname.toString());

        frappe

        .call({

            method: 'ddmrp.ddmrp.doctype.demand_estimate.demand_estimate.create_demand',

            freeze: true,

            args: {

                docnames: docnames                  

            }

        })

        .then((r) => {

            let cnt = r.message;

            if (cnt) frappe.msgprint('Created ' + cnt + ' demand estimate records')

        });           

    });

}

};

2 Likes

it is not working on the list view…or i am doing something wrong ?

Right, my post described adding a custom button to the form view. See the wiki on how to customize the list view:

https://frappeframework.com/docs/v13/user/en/api/list