---
title: "Document Functions"
space: "Wiki"
url: "https://support.aakvatech.com/wiki/document-functions"
updated: "2026-07-22"
---

Here’s a list of functions supported by the `BaseDocument` class and related utilities in the provided script:

### Core Functions
1. **`__init__(self, d)`** - Initialize a document instance.
2. **`update(self, d)`** - Update multiple fields using a dictionary.
3. **`update_if_missing(self, d)`** - Set default values for fields without existing values.
4. **`get(self, key, filters=None, limit=None, default=None)`** - Retrieve a field's value or child table rows with optional filters.
5. **`getone(self, key, filters=None)`** - Retrieve a single matching child document.
6. **`set(self, key, value, as_value=False)`** - Set a field's value or initialize child tables.
7. **`delete_key(self, key)`** - Delete a field from the document.
8. **`append(self, key, value=None)`** - Add a new row to a child table.
9. **`extend(self, key, value)`** - Add multiple rows to a child table.
10. **`remove(self, doc)`** - Remove a child document from a child table.
11. **`as_dict(self, ...)`** - Serialize the document as a dictionary.
12. **`as_json(self)`** - Serialize the document as JSON.
13. **`get_valid_dict(self, ...)`** - Retrieve a dictionary of valid fields for database insertion.
14. **`get_table_field_doctype(self, fieldname)`** - Get the doctype of a child table.
15. **`db_insert(self, ignore_if_duplicate=False)`** - Insert the document into the database.
16. **`db_update(self)`** - Update the document in the database.
17. **`db_update_all(self)`** - Update the document and all child documents in the database.
18. **`get_db_value(self, key)`** - Retrieve a field's value from the database.
19. **`get_parentfield_of_doctype(self, doctype)`** - Get the parent fieldname for a given child doctype.
20. **`update_modified(self)`** - Update the `modified` timestamp in the database.

### Validation
21. **`_validate_length(self)`** - Validate length constraints for fields.
22. **`_validate_selects(self)`** - Validate `Select` field values against options.
23. **`_validate_data_fields(self)`** - Validate `Data` fields (e.g., email, URL).
24. **`_validate_constants(self)`** - Validate fields marked as "set only once."
25. **`_validate_update_after_submit(self)`** - Validate updates after document submission.
26. **`_validate_non_negative(self)`** - Ensure numeric fields are not negative.
27. **`_validate_code_fields(self)`** - Validate fields containing code (e.g., Python expressions).
28. **`_validate_links(self)`** - Check for invalid or canceled links in linked fields.
29. **`_validate_mandatory(self)`** - Validate mandatory fields.

### Document Metadata and Utility
30. **`is_new(self)`** - Check if the document is new.
31. **`get_formatted(self, fieldname, ...)`** - Retrieve a formatted version of a field's value.
32. **`precision(self, fieldname, parentfield=None)`** - Get precision for numeric fields.
33. **`is_print_hide(self, fieldname, ...)`** - Check if a field is hidden for print.
34. **`in_format_data(self, fieldname)`** - Check if a field is part of the print format data.
35. **`init_child_tables(self)`** - Initialize child tables for the document.
36. **`init_valid_columns(self)`** - Initialize valid columns with default values.
37. **`get_valid_columns(self)`** - Retrieve a list of valid columns for the document.

### Field and Link Management
38. **`set_fetch_from_value(self, doctype, df, values)`** - Set value for fields with `fetch_from` property.
39. **`get_invalid_links(self, is_submittable=False)`** - Retrieve invalid or canceled links.

### Password Management
40. **`_save_passwords(self)`** - Save password field values securely.
41. **`get_password(self, fieldname="password", raise_exception=True)`** - Retrieve a password securely.
42. **`is_dummy_password(self, pwd)`** - Check if a password is a dummy (e.g., `*****`).

### Error Handling
43. **`show_unique_validation_message(self, e)`** - Show validation errors for unique constraints.
44. **`throw_length_exceeded_error(self, df, max_length, value)`** - Raise an error for exceeded length constraints.

### Miscellaneous
45. **`get_label_from_fieldname(self, fieldname)`** - Get the label for a fieldname.
46. **`get_value(self, fieldname)`** - Get a value for a field, casting it appropriately.
47. **`cast(self, value, df)`** - Cast a value based on field type.
48. **`_sanitize_content(self)`** - Sanitize HTML and email fields to prevent XSS.
49. **`_fix_numeric_types(self)`** - Ensure numeric fields have consistent types.
50. **`_extract_images_from_text_editor(self)`** - Extract images embedded in `Text Editor` fields.
51. **`reset_values_if_no_permlevel_access(self, ...)`** - Reset fields based on permission levels.

This comprehensive list covers all primary methods defined in the script for interacting with, validating, and managing documents in the Frappe framework.