I am looking for a Custom Script, to copy a particular field from the Parent Form into the Child Form.
For eg,
In Doctype,
Delivery Note (Parent) there is a field A, and Delivery Note Item (Child) has a field B, When I put data in field A in the parent table, The data should be copied into Field B in the child table.
frappe.ui.form.on("Delivery Note","a", function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[x].b = cur_frm.doc.a //b is your child table field name.
}
cur_frm.refresh_field('items')
});
I tried this, it did not work, I used in both Delivery Note and Delivery Note Item,
frappe.ui.form.on("Delivery Note","test_1", function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[x].d_date = cur_frm.doc.test_1
}
cur_frm.refresh_field('items')
});
but when I put an underscore as shown below, It makes the field test_1 in delivery note go blank once I add an item into the delivery note.
frappe.ui.form.on("Delivery_Note","test_1", function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[x].d_date = cur_frm.doc.test_1
}
cur_frm.refresh_field('items')
});
What am I doing wrong?
While using this script I find there is a problem when multiple items were added while using the above code. It only copies the value into first Item. After I changed the condition to Validate it solves that issue.
I am posting it here so it can help someone else
frappe.ui.form.on("Delivery Note","validate", function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[i].d_date = cur_frm.doc.test_1
}
cur_frm.refresh_field('items')
});
I am having same issue
trying to set cost_center in sales invoice item grid via a custom field cost_center on sales invoice.
frappe.ui.form.on(“Sales Invoice”,“validate”,function() {
var row = frappe.get_doc(cdt, cdn);
if(doc.cost_center) {
row.cost_center = doc.cost_center;
refresh_field(“cost_center”, cdn, “items”);
} else {
this.frm.script_manager.copy_from_first_row(“items”, row, [“cost_center”]);
}
}
);