Hi , I’ve similar issue and Not solved, may you please help
I’ve a Customs doctype “Project Track Record” which includes child table under name SCOPE with the same fields names of sales order items, I need to use “Get Items from Sales Order” and used below custom script but get nothing:
frappe.ui.form.on(‘Project Track Record’, {
refresh: function(frm) {
frm.add_custom_button(__(“Get items from sales order”), function() {
show_so_dialog(frm);
});
}
});
function show_so_dialog(frm) {
frappe.prompt([
{‘fieldname’: ‘sales_order’, ‘fieldtype’: ‘Link’, ‘label’: ‘Sales Order’, ‘reqd’: 1, ‘options’: ‘Sales Order’}
],
function(sales_order){
console.log(sales_order.sales_order);
get_items_from_so(sales_order.sales_order);
},
‘Get items from sales order’,
‘Get items’
)
}
function get_items_from_so(sales_order) {
frappe.call({
“method”: “frappe.client.get”,
“args”: {
“doctype”: “Sales Order”,
“name”: sales_Order
},
“callback”: function(response) {
// add items to your child table
var so = response.message;
so.items.forEach(function (item) {
var child = cur_frm.add_child(‘items’);
frappe.model.set_value(child.doctype, child.scope, ‘item_code’, item.item_code);
frappe.model.set_value(child.doctype, child.scope, ‘item_name’, item.item_name);
frappe.model.set_value(child.doctype, child.scope, ‘description’, item.description);
frappe.model.set_value(child.doctype, child.scope, ‘stock_uom’, item.stock_uom);
frappe.model.set_value(child.doctype, child.scope, ‘price_list_rate’, item.price_list_rate);
});
cur_frm.refresh_field(‘items’);
}
});
}