Actions & Links in Frappe Framework (v15)
Actions and Links (also called Connections) introduce additional interaction capabilities in DocTypes.
What are Actions?
Actions are buttons defined on a DocType’s form view which trigger a specific server method or redirect to a route. They enable custom workflows, quick commands, or external integrations without modifying the core UI logic. Frappe Docs
Supported Action types
Server Action: Calls a whitelisted python function via @frappe.whitelist. Frappe Docs
Route: Redirects the user to a specific route (URL) when clicked.
How to configure an Action
In your app, define a whitelisted server method, e.g.:
import frappe
@frappe.whitelist()
def my_custom_action(docname, **kwargs):
# your custom logic here
frappe.msgprint(f"Action triggered for {docname}")
- In your DocType definition (UI or JSON), configure the action with the method path and optionally a label.
- Example configuration snippet (as shown in official docs) uses the “Action Config” section.
- On the DocType form view, the action appears as a button labelled accordingly.
Use Case Example
Suppose you want a “Generate Invoice PDF” button on a Sales Order form:
- Define method generate_invoice_pdf(sales_order)
- Configure an Action named “Generate PDF” that calls this method
- When clicked, the system executes the server method and returns an appropriate response (download link, message, etc.)
What are Links (Connections)?
Links, also referred to as Connections, show related DocTypes or records on a DocType dashboard. They facilitate navigation from one document to its related documents.
How Links work
- In the Connections section of a DocType’s view, similar or related document types are listed, showing which records are linked to this document.
- This is helpful for parent ↔ child relationships and cross-DocType navigation.
Configuration of Links
You create a <doctype>_dashboard.py file that defines a get_data() function returning connection definitions. Example from ERPNext:
from frappe import _
def get_data():
return {
"fieldname": "sales_invoice",
"transactions": [
{
"label": _("Payments"),
"items": ["Payment Entry"]
}
]
}
This instructs Frappe to show “Payments” related to this Sales Invoice in the Connections section.
Internal Links (Child Table)
You can define links that navigate to child table entries or other related DocTypes via the same mechanism of dashboard configuration. Frappe Docs
Why Use Actions & Links?
- Improve user experience: Provide contextually relevant buttons and navigation paths.
- Streamline workflows: Trigger complex logic with single click via Actions.
- Increase document connectivity: Show related records dynamically via Links.
- Enhance maintainability: Configuration-based setup without major code changes.
Implementation Details in Frappe v15
- The Actions & Links feature was introduced in version 12.1 of Frappe. Frappe Docs
- In Frappe v15, they work as part of DocType metadata and client-server integration:
- Actions execute via whitelisted methods (frappe.whitelist)
- Links populate via get_data() in dashboard files
UI reflects these configurations under Form View → Connections and Form View → Action Buttons
Best Practices & Tips
- Keep action methods lean: avoid heavy processing inside button logic; consider background jobs if needed.
- Use clear labels for action buttons to reflect business context (e.g., “Submit for Approval”, “Create Return”).
- Limit the number of action buttons to avoid UI clutter.
- Use connections to show only relevant related DocTypes for that document; ensure get_data() filters properly.
- Document actions and links in your app README for easier maintenance and onboarding.
Troubleshooting Common Issues
| Symptom | Likely Cause | Solution |
| Action button not showing | DocType action not configured or method not whitelisted | Ensure action is defined in UI/JSON, and method decorated with @frappe.whitelist |
| Link section empty | get_data() not returning correct structure or filter mismatch | Verify dashboard.py includes correct fieldname, transactions, and items |
| Action fails silently | Method error or incorrect parameters | Check server logs, ensure docname is passed, method returns expected value |
| UI performance lag | Many connections or heavy actions on load | Limit items in get_data(), load heavy logic asynchronously |
Real-World Example: Sales Invoice DocType
In ERPNext (built on Frappe v15), the Sales Invoice DocType uses Actions & Links as follows:
- An Action button “Create Payment Entry” triggers the server method to generate payment entry.
- In the Connections section, “Delivery Notes”, “Payments”, “Tax Records” appear, showing linked documents and enabling quick navigation.
(This is derived from the official Frappe docs for Actions & Links.) Frappe Docs
FAQs
Q: What is a DocType Action in Frappe v15?
A: A DocType Action is a configurable button on the form view that triggers a server method or route when clicked.
Q: What is a Link (Connection) in a DocType?
A: A Link (Connection) shows related DocTypes or records in the dashboard of a document, enabling quick navigation.
Q: Can I add Actions and Links to custom DocTypes?
A: Yes—custom DocTypes support Actions via whitelisted methods and Links via dashboard.py configuration.
Q: Do Actions & Links require code?
A: Yes—for Actions you need a server method; for Links you need to configure get_data() in dashboard.py.
Summary
Actions & Links in Frappe Framework v15 are powerful mechanisms to extend DocType interactivity and navigation without major UI redesign. By configuring server-side methods for Actions and dashboard connections for Links, you can tailor workflows and document connectivity for ERPNext, custom apps, and business-specific requirements.