Frappe Doctype Lifecycle Explained From Form Load to Submission| Sabbirz | Blog

Frappe Doctype Lifecycle Explained From Form Load to Submission

Frappe DocType Thumbnail

Complete CRUD Lifecycle in Frappe

A CRUD (Create, Read, Update, Delete) operation in Frappe follows a structured lifecycle that ensures smooth data handling from form rendering to submission. Below is the step-by-step execution flow:

Frappe Doctype LifeCycle

1. Loading the Form

When a user accesses a form in Frappe, the system follows these steps:

  • Fetch the DocType metadata from the JSON file.
  • Load the necessary JavaScript to manage client-side interactions.
  • Apply any custom HTML and CSS (if defined).
  • Render the form dynamically on the client side.

2. Interacting with the Form

At this stage, the user interacts with the form:

  • The form runs client-side JavaScript validations and logic.
  • The user modifies, adds, or deletes data within the form fields.

3. Saving the Form

When the user clicks the Save button:

  • Client-side validation is triggered (validate event in JavaScript).
  • Data is sent to the server via an API request.
  • Server-side hooks execute in this order:
    • before_save
    • before_insert
    • validate
    • on_update

These Python methods ensure data integrity before committing changes to the database.

4. Submitting the Form (If Applicable)

For forms that require submission (e.g., Sales Invoice, Purchase Order):

  • Client-side JavaScript executes the on_submit event.
  • Server-side submission hooks run:
    • on_submit (executed in Python).

This marks the document as submitted and final, preventing further direct modifications.

5. Post-Save Events & Dashboard Rendering

After the form is saved or submitted:

  • The system renders the dashboard (if defined for the DocType).
  • Any workflows, background jobs, or scheduled tasks are triggered.

Conclusion

The Frappe DocType lifecycle ensures structured data processing, enforcing client-side and server-side validations at the right stages. This systematic approach guarantees smooth data presentation, validation, and business logic execution.

Related posts