[Tutorial] Add custom action button. custom menu button, custom icon button in form view

Hello,

We can add Custom button in form to perform some actions.

Custom button:
cb1

Syntax:

cur_frm.add_custom_button(__("Show Info"), function() {
    frappe.msgprint("Custom Information");
    }); 

`
As custom buttons added in form inner toolbar, developer can have specific use-case to add custom button in Menu or action.
e.g Using action menu level custom button we can have dynamic workflow.

1) Adding custom action button, same as workflow actions.
e.g Approve By Account Lead
cb5

Syntax:

cur_frm.page.add_action_item(__("Approve by AR Lead"), function() {
	frappe.msgprint("Approved");
	cur_frm.trigger('approve');
});

Note: cur_frm.trigger will trigger frappe js code.

2) Adding menu button “Custom Print” in form menu.
cb2

Syntax:

cur_frm.page.add_menu_item(__("Custom Print"), function() {
	frappe.msgprint("Printed Document");
	cur_frm.print_doc();
});

3) Custom Action Icon similar to Print Icon for Email.
It will help end user to perform some action quickly and avoid unnecessary clicks.
cb4

Syntax:

cur_frm.page.add_action_icon(__("fa fa-envelope-o"), function() {
	frappe.msgprint("Custom email or print");
	new frappe.views.CommunicationComposer();
});
  1. adding color on custom action icons
    cb55

    cur_frm.page.add_action_icon(__(“fa fa-envelope-o text-success”), function() {
    frappe.msgprint(“email”);
    new frappe.views.CommunicationComposer();
    });

    cur_frm.page.add_action_icon(__(“fa fa-car text-warning”), function() {
    frappe.msgprint(“get_doc_info”);
    cur_frm.trigger(‘get_doc_info’);
    });

67 Likes

Thank you for your contribution.

For total noobs like myself, would you please take a few steps back. to explain where to make that changes in your example?

1 Like

You make the changes in the .js file of the doctype you are modifying. For example, if you were editing the BOM doctype in the manufacturing module, you would edit bom.js in the folder structure shown below:

6 Likes

Wonderful. This is a great starting point for me.

1 Like

Other good starting points that I found was going through the Library App tutorial on the Frappe website and working through the Meeting App tutorial on Youtube.

2 Likes

Thanks a lot babe :heart: , just what I needed

1 Like

@kolate_sambhaji thanks a lot

1 Like

thanks a lot

1 Like