Here’s an example on how to fetch child table values before a document is saved. Works for values imported by code and manually updated. This particular Client Script example fetches the Customer Purchase Order number onto a custom column on the Production Plan:
frappe.ui.form.on('Production Plan', {
setup(frm) {
const sos = frm.get_field('sales_orders');
// replace the refresh function
sos.refresh_super = sos.refresh;
sos.refresh = () => {
sos.refresh_super();
for (const row_name in sos.grid.grid_rows_by_docname) {
frm.trigger('sales_order', 'Production Plan Sales Order', row_name);
}
}
},
});
frappe.ui.form.on('Production Plan Sales Order', {
sales_order(frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (row.sales_order) {
frappe.model.with_doc('Sales Order', row.sales_order, function () {
const so = frappe.model.get_doc('Sales Order', row.sales_order);
frappe.model.set_value(cdt, cdn, 'po_no', so.po_no);
});
}
},
});