My scenario/use case is :
in target child table (sales order item), there is 1 field name customer item description which should copy/fetched from source child table (Item Customer Detail) field name ref description. I’ve tried with numbers of tutorials listed in this forum but none of them able to fetch the data.
codes :
frappe.ui.form.on('Sales Order', {
onload: function (frm) {
if (frm.doc.item_code) {
frm.clear_table('items');
frappe.model.with_doc('Item', frm.doc.item_code, function() {
let source_doc = frappe.model.get_doc('Item', frm.doc.item_code);
$.each(source_doc.customer_items, function (index, source_row) {
var addChild = cur_frm.add_child("items");
addChild.ref_description = source_row.ref_description;
frm.refresh_field("items");
});
});
}
}
});
No error no anything. Nothing is prompted for me to trace back the error. Can anyone help me to point out where/why it is not working ? And where should I make the corrections ? let me know if you need any other information. I’ll attach on the next reply.
@bella.zahar
Hello i am trying to fetch data from child table to another but it is not working with me
i want to fetch the qty in sales order item table at sales order doctype to delivery note item table at delivery note doctype but it not working can you help me in this
this is my code
frappe.ui.form.on(“Delivery Note”, {
on_load: function(frm) {
if(frm.doc.sales_order) {
frm.doc.items.forEach(function(dn_item) {
var sales_order_item = dn_item.sales_order_item;
if(sales_order_item) {
frappe.model.with_doc("Sales Order Item", sales_order_item, function() {
var so_item = frappe.model.get_doc("Sales Order Item", sales_order_item);
var qty = so_item.qty;
frappe.model.set_value(
"Delivery Note Item",
dn_item.name,
"qty_ordered",
qty
);
});
}
});
frappe.run_serially(function() {
frm.refresh();
});
}
@yara
If you create DN from Sales Order it should be fetched automatically or if you create DN, you can have Get Items From> Sales Order to import everything. It is not clear why you need to do it with script. This is a working script:
@rapidweb
Thank you for your reply
i want to fetch qty ,delivery date and delivered qty to make a custom print format and show remaining qty because the company sales to customer and deliver them in separate times and qty
it not fetched automatically although in other doctype when i add custom field with same label it fetched from the linked document
i will try your code thanks