I made it work using get_route_options_for_new_doc.
If the field is inside a child table grid, you must specify both the table field name and the field name inside the grid in get_docfield.
Just place the script inside the parent doctype’s client script.
Please replace “Doctype Name”, “table_field_name”, “grid_field_name”, “quick_entry_field_name”, and “test_value” with your actual field names and values.
frappe.ui.form.on("Doctype Name", {
refresh: function(frm) {
let batch_field = frm.get_docfield("table_field_name", "grid_field_name");
batch_field.get_route_options_for_new_doc = function (row) {
if (frm.is_new()) return;
return {
"quick_entry_field_name": "test_value",
};
}
If the field is not in a child table (i.e., a top-level field), you only need to pass the field name directly to get_docfield.
frappe.ui.form.on("Doctype Name", {
refresh: function(frm) {
let batch_field = frm.get_docfield("field_name");
batch_field.get_route_options_for_new_doc = function (row) {
if (frm.is_new()) return;
return {
"quick_entry_field_name": "test_value",
};
}