Hi,
I have a scenerio where I created two master field on sales order named style and brand.
Now, I need to pull this style and brand on delivery notes item level while I pull the data from Sales Order.
I have write down a script to puopulate this feilds as below:
function populate_so_related_fields(frm) {
if (!frm.doc.items || !frm.doc.items.length) return;
frm.doc.items.forEach(row => {
// Must be mapped from Sales Order
if (!row.sales_order) return;
if (!row.custom_po_no) {
frappe.call({
method: "getPOandStyle",
args: {
sales_order: row.sales_order
},
callback: function (r) {
if (r) {
frappe.model.set_value(row.doctype, row.name, "custom_po_no", r.message.po_no);
frappe.model.set_value(row.doctype, row.name, "custom_style", r.message.custom_style);
frappe.model.set_value(row.doctype, row.name, "custom_brand", r.message.custom_brand);
}
}
})
}
})
}
Now I am wondering on which event I will call this function.
any idea?