Custom Fields
Custom fields allow you to add new fields to existing DocTypes without modifying the core schema.Adding Custom Fields via UI
Navigate to Customize Form
Go to Home > Customization > Form > Customize Form or search for “Customize Form”.
Add New Field
Click Add Row in the Fields table and configure:
- Label: Display name for the field
- Type: Field type (Data, Link, Select, Text, etc.)
- Options: For Link/Select fields, specify the linked DocType or options
- Insert After: Position in the form
- Mandatory: Whether the field is required
Custom fields are prefixed with
custom_ in the database to distinguish them from standard fields.Adding Custom Fields Programmatically
Use thecreate_custom_fields function for bulk field creation:
Field Types
| Field Type | Description | Use Case |
|---|---|---|
| Data | Single line text | Short text values |
| Text | Multi-line text | Long descriptions |
| Select | Dropdown with predefined options | Status, categories |
| Link | Link to another DocType | Foreign key relationships |
| Table | Child table | Line items, details |
| Check | Checkbox (0 or 1) | Boolean flags |
| Date | Date picker | Dates without time |
| Datetime | Date and time picker | Timestamps |
| Currency | Formatted currency | Monetary values |
| Int | Integer number | Quantities, counts |
| Float | Decimal number | Measurements |
| Attach | File upload | Documents, images |
| Attach Image | Image upload with preview | Photos, logos |
| Code | Code editor | JSON, scripts |
| HTML | Rich text editor | Formatted content |
Property Setters
Property Setters override default properties of DocType fields without creating custom fields.Using Property Setters
Common Property Overrides
| Property | Type | Description |
|---|---|---|
hidden | Check | Hide/show field |
reqd | Check | Make field mandatory |
read_only | Check | Make field read-only |
allow_on_submit | Check | Allow editing after submit |
label | Data | Change field label |
default | Data | Set default value |
options | Text | Update field options |
depends_on | Data | Conditional display |
precision | Select | Decimal places for numbers |
Example: Toggle Rounded Total
Custom Scripts
Client Scripts add custom JavaScript to DocType forms for dynamic behavior.Creating Client Scripts
Create New Script
Click New and configure:
- Name: Descriptive name for the script
- DocType: The DocType this script applies to
- Script Type: When the script runs (Form, List, etc.)
Client Script Examples
Auto-calculate Field Values
Auto-calculate Field Values
Add Custom Buttons
Add Custom Buttons
Filter Link Fields
Filter Link Fields
Validate Before Save
Validate Before Save
Server Scripts
Server Scripts add custom Python logic that runs on the server.Creating Server Scripts
Create New Script
Configure:
- Script Type: DocType Event, API, or Permission Query
- DocType: Target DocType (for DocType Events)
- Event: before_save, after_insert, on_submit, etc.
Server Script Examples
Auto-generate Serial Numbers
Auto-generate Serial Numbers
Send Email Notifications
Send Email Notifications
Update Related Documents
Update Related Documents
Workflows
Workflows define approval processes and state transitions for documents.Creating a Workflow
Configure Basic Settings
- Document Type: Select the DocType (e.g., Leave Application)
- Workflow Name: Descriptive name
- Is Active: Enable the workflow
Define Transitions
Configure allowed state changes:
- From Draft to Pending Approval (Submit)
- From Pending Approval to Approved (Approve)
- From Pending Approval to Rejected (Reject)
Workflows override the standard Submit/Cancel workflow. Once a workflow is active, documents follow the workflow states instead.
Custom DocTypes
Create entirely new DocTypes for business processes not covered by standard ERPNext.Creating Custom DocTypes
Create New DocType
Click New and configure:
- Name: DocType name (e.g., “Warranty Claim”)
- Module: Which module it belongs to
- Is Submittable: Whether documents can be submitted and cancelled
- Is Child Table: Whether it’s used as a child table in other DocTypes
Print Formats
Customize how documents are printed or exported as PDF.Creating Print Formats
Navigate to Print Format Builder
Open any document and click the printer icon, then select “Edit Format” or go to Home > Customization > Print Format.
Print Format Example
Best Practices
Customization Strategy
Performance Considerations
- Minimize database queries in client scripts
- Use server scripts for heavy processing
- Cache frequently accessed data
- Index custom fields that are frequently queried
- Test customizations with production-like data volumes
Documentation
- Document all customizations in a central location
- Include the business reason for each customization
- Note dependencies between customizations
- Keep track of which customizations affect which DocTypes
Testing
Test in Development First
Always test customizations in a development environment before production.