How to update data inside the table?

I created a new doctype Issue Services and I added a table stock entry details and I created a button to create a new_doc but when I map the data from material request to Issue Services it doesn’t trigger the event to update the item details like uom, basic_rate, and calculate the basic amount so to calculate you have to select the item code again. How can I make this work? Thank you for helping.

You have to use the frappe.model.set_value so item-related details will automativally update.

1 Like

Hello @NCP . I tried using frappe.model.set_value but it’s not working but I am not really sure maybe it’s in my code.

    if (frm.doc.docstatus === 1 && frm.doc.material_request_type === 'Material Issue'){
        frm.add_custom_button(__("Issue Services"), function(){
            frappe.call({
                method: "fetch_material_issuance",
                args: {
                    dn: frm.doc.name,
                },
                callback:function(r){
                    if(!r.exc){
                        items = []
                        frappe.model.sync(r.message);
                        frappe.set_route("Form", r.message.doctype, r.message.name);
                        
                        r.message.items.forEach(arr => {
                            items.push(arr.item_code)
                        })
                        setTimeout(() => {
                            frm.doc.items.forEach((row, index) => {
                                frappe.model.set_value(row.doctype, row.name, 'item_code', items[index])
                            })
                        }, 2000); 
                        
                        frm.refresh_field('items')
                    }
                }
            })
        }, __("Create"))
    }

@frappe.whitelist()
def fetch_material_issuance(dn):
mir_doc = frappe.get_doc(“Material Request”, dn)
i_services = frappe.new_doc(“Issue Services”)
i_services.update({
“posting_date”: mir_doc.transaction_date,
“notes”: mir_doc.custom_notes,
“company”: mir_doc.company
})
for item in mir_doc.items:
i_services.append(“items”, {
“t_warehouse”: item.warehouse,
“item_code”: item.item_code,
“qty”: item.qty,
“uom”: item.uom,
“stock_uom”: item.stock_uom,
“description”: item.description,
“item_group”: item.item_group,
“expense_account”: item.expense_account,
“cost_center”: item.cost_center,
“project”: item.project
})
return i_services.as_dict()