Accessing Child Table Data Too Early (Custom script does not work sometimes)

In my case:

i made a logic to fill the child table with certain data after the document is loades,
but the problem was the child table not exist yet so i needed to reload the document by myself.

what was my solution?

frappe.ui.form.on('Your Doctype', {
    onload_post_render: function(frm) {
        frappe.after_ajax(() => {
            // your logic here
        });
    }
}

Use frappe.after_ajax inside onload_post_render when you need to:

  • Wait for all data (especially child tables) to be ready,
  • And only then run your logic.
  1. onload_post_render This hook runs after the form is loaded and its HTML is shown. But sometimes, even after that, some data (like child tables) is still being loaded in the background using AJAX.

  2. frappe.after_ajax This tells Frappe:
    β€œWait until all background AJAX calls are finished, then run my code.”
    So your code inside this block will only run after:

    • The child tables are fully loaded,
    • The server has returned all data,
    • Everything is ready to use.

This solution avoids bugs that happen when trying to access data too early β€” like:

  • Missing rows in child tables,
  • Empty fields,
  • Or logic not applying correctly.
2 Likes