The DefaultValue Doctype in Frappe is a child table (istable: 1) designed to store key-value pairs that represent default settings or preferences. It is primarily used as a child table within the "User" and "Role" Doctypes, and can also be managed via the "User Properties" page.
- To allow the definition of default values for various system parameters or field values on a per-user or per-role basis.
- To provide a flexible mechanism for users to personalize their experience or for administrators to set common defaults for groups of users (via Roles).
- To enable other Doctypes or system logic to fetch these defaults at runtime to pre-fill fields or control behavior.
defaultvalue.json: Defines the schema (fields, properties) of this child Doctype.defaultvalue.py: Contains the basic server-side Python controller class and index creation logic.README.md: Provides a brief overview of its purpose and usage context.
This Doctype does not have a dedicated client-side JavaScript (.js) file, as its interaction is typically managed by the parent Doctype's UI or specific settings pages like "User Properties".
This JSON file specifies the structure for each row in the "DefaultValue" child table.
istable: 1: This flag explicitly marks it as a child Doctype.autoname: "hash": Each default value entry is assigned a unique hash ID.- Key Fields:
defkey(Data, Required, In List View):- This field stores the "Key" or identifier for the default setting.
- This key often corresponds to a fieldname in another Doctype (e.g., "language", "country", "naming_series") or a specific system setting identifier.
defvalue(Text, In List View):- This field stores the actual "Value" to be used as the default for the corresponding
defkey. - The
fieldtypeis "Text", allowing it to store various types of default data (strings, numbers, simple JSON strings, etc.). The interpretation of this value is handled by the logic that consumes these defaults.
- This field stores the actual "Value" to be used as the default for the corresponding
- Permissions:
- The
permissionsarray is empty ([]). As a child table, its editability and visibility are controlled by the permissions set on its parent Doctype (e.g., "User" or "Role").
- The
- Module: "Core"
The Python controller for this Doctype is minimal, focusing on database optimization.
DefaultValue(Document)Class:- This is the standard class definition inheriting from
frappe.model.document.Document. - The
passstatement indicates that no custom server-side methods (likevalidate,on_updatespecific to the default value row itself) are implemented in this controller. - The logic for applying these default values when new documents are created or when settings are fetched is handled by Frappe's core
frappe.defaultsmodule and by the controllers of Doctypes that utilize these defaults.
- This is the standard class definition inheriting from
on_doctype_update()(Global Function):- This function is executed during
bench migrate. - It ensures that database indexes are created on the
tabDefaultValuetable:- An index on
(parent, defkey): This is crucial for performance when the system needs to quickly fetch a specific default value (identified bydefkey) for a particular parent document (e.g., the default "Company" for User "john.doe@example.com"). - An index on
(parent, parenttype): A more general index for querying child table records.
- An index on
- This function is executed during
The README succinctly states: "Child table for User and Role where default keys and values are stored. They can also be created from the User Properties page."
The "DefaultValue" Doctype allows for setting defaults in various contexts:
- User Defaults (via "User" Doctype or "User Properties" page):
- A user (or an administrator editing a user's record) can set personal defaults.
- Example: User "jane.doe@example.com" might set:
defkey: "country",defvalue: "Germany"defkey: "language",defvalue: "de"
- When Jane creates a new "Address" document, the "Country" field might automatically be pre-filled with "Germany" if the Address Doctype is configured to fetch this default.
- Role Defaults (via "Role" Doctype):
- An administrator can set defaults that apply to all users having a particular role.
- Example: For the "Sales User" role:
defkey: "naming_series" (for Sales Order),defvalue: "SO-"
- When a "Sales User" creates a new "Sales Order", the "Naming Series" might default to "SO-".
- System-Wide Defaults (Historically, some might have been set via "System Settings" or similar parent Doctypes using DefaultValue):
- While many system-wide defaults are now managed in dedicated "Settings" Doctypes, the DefaultValue mechanism provides a flexible fallback.
- Fetching Defaults:
- Frappe provides utility functions like
frappe.defaults.get_user_default(key),frappe.defaults.get_global_default(key), andfrappe.defaults.get_defaults()which query thetabDefaultValuetable (among other places like "System Settings") to retrieve these values. The system typically checks for user-specific defaults first, then role-based defaults, then global defaults.
- Frappe provides utility functions like
The DefaultValue Doctype is a key component in making Frappe adaptable and user-friendly by allowing pre-configuration of common values, reducing repetitive data entry.