Customize Form - Actions Table
The actions
table in the Customize Form Doctype allows users to define custom actions or buttons for the selected Doctype. Each row in the actions
table represents a specific action and includes fields that determine its behavior and functionality. Below is a breakdown of each field in the actions
table and its usage:
1. label
- Description: The text displayed on the action button.
- Use: Describes the purpose of the action. For example, "Approve," "Reject," or "Send Email."
2. action_type
- Description: Specifies the type of action to be performed.
- Use:
- Common options include:
- Server Script: Executes a server-side script.
- Client Script: Runs a client-side script.
- Route: Redirects to another page or view.
- Link: Opens a specific record or external link.
- Example: Set
action_type
to "Server Script" to trigger backend logic when the button is clicked.
- Common options include:
3. action
- Description: Defines the action to be performed, such as a JavaScript function or server method.
- Use:
- If
action_type
is "Server Script," specify the method to call (e.g.,frappe.call
). - If
action_type
is "Route," specify the route to navigate to (e.g.,/app/sales-invoice
). - If
action_type
is "Client Script," include the JavaScript code to execute. - Example:
function() { frappe.msgprint("Action performed!"); }
- If
4. group
- Description: Categorizes the action under a specific group.
- Use: Organize actions into logical groups in the UI. For example:
- Group related actions such as "Send Email" and "Print Invoice" under "Communication."
5. hidden
- Description: Indicates whether the action should be hidden from the user interface.
- Use: Hide actions that are only intended for specific users or scenarios, or when actions are temporarily disabled.
6. idx
- Description: Sequence number of the action in the list.
- Use: Determines the display order of actions in the UI.
Examples of Usage:
Approve Button:
label
: Approveaction_type
: Server Scriptaction
:custom_app.approve_document
- Use: Adds an "Approve" button that calls a server-side function to approve the document.
Redirect to Another Doctype:
label
: View Related Invoicesaction_type
: Routeaction
:/app/sales-invoice
- Use: Adds a button that redirects users to the Sales Invoice list view.
Trigger Client-Side Logic:
label
: Show Alertaction_type
: Client Scriptaction
:function() { frappe.msgprint("This is a custom alert."); }
- Use: Adds a button that displays a custom alert when clicked.
Hidden Action for Admin Use:
label
: Reset Settingsaction_type
: Server Scriptaction
:custom_app.reset_settings
hidden
: Checked- Use: Provides a backend utility accessible only to administrators.
Grouped Actions:
label
: Email Customeraction_type
: Server Scriptaction
:custom_app.send_email
group
: Communication- Use: Organize all communication-related actions under a single group.
By using the actions
table, you can add powerful custom buttons to a Doctype, enhancing its functionality and streamlining workflows. These actions can be tailored to meet specific business requirements and improve the user experience.