Hi Experts,
I need to copy Required Qty from child table to Work Order customize field.
I have tried using fetch, but still not working.
I have tried some code but still not working. I am afraid, there is something wrong with my code.
I need to copy field in the red square to my customize field.
Any suggestion?
Best Regards,
Enggar
Hello @cloudeater ,
Check out this developer-cheatsheet for achieving the task you want to perform.
Also, what code have you used to achieve the same?
Thanks & Regards,
Kalpit Shah
1 Like
Hello,
Thank you for your reply.
Here is my code:
frappe.ui.form.on("Work Order","ng", function(frm){
cur_frm.doc.ng_weight += cur_frm.add_fetch('work_order_item', 'required_qty', 'ng_weight');;
cur_frm.refresh_field('ng_weight');
});
Best Regards,
Enggar
frappe.ui.form.on("Work Order Item","required_qty", function(frm){
var required_quantity=0;
for(var i=0;i<cur_frm.doc.work_order_item.length;i++){
required_quantity+=parseFloat(cur_frm.doc.work_order_item[i].required_qty);
}
cur_frm.doc.ng_weight=parseFloat(required_quantity);
cur_frm.refresh_fields("ng_weight");
});
1 Like
when you write this
does this mean I have to put the custom script in the Work Order Item doctype?
Keep this custom script in Work Order Doctype.
1 Like
I have tried the code you give.
My customize field in the Work Order is ng_weight and I edit the required_quantity to required_qty because the field name in the Work Order Item is required_qty.
But still not working.
Any traceback/screenshots would help me to understand the situation.
As you’ve said, I’ve changed the code. Try it out!
Here is the screen shot of my Work Order.
I need the Production Weight value to be inserted in my custom field (ng_weight)
The value show up when I inserted the value in the NG field.
The other field works by using this code because the field still in the same doctype, but the Production Weight is in other doctype. Its in Work Order Item.
frappe.ui.form.on("Work Order","uom", function(frm){
cur_frm.doc.total_inject += cur_frm.doc.qty / cur_frm.doc.uom;
cur_frm.doc.shot = cur_frm.doc.total_inject;
cur_frm.refresh_field('shot');
cur_frm.refresh_field('total_inject');
});
Because Production Order is in Work Order Item doctype, thats why I am using this code below.
frappe.ui.form.on("Work Order","ng", function(frm){
cur_frm.doc.ng_weight += cur_frm.add_fetch('work_order_item', 'required_qty', 'ng_weight');;
cur_frm.refresh_field('ng_weight');
});
Then I change the code to yours, but still not working.
Sorry if my explanation kind of confusing to you, I hope you got it.
@cloudeater
cloudeater:
frappe.ui.form.on(“Work Order”,“ng”, function(frm){ cur_frm.doc.ng_weight += cur_frm.add_fetch(‘work_order_item’, ‘required_qty’, ‘ng_weight’);; cur_frm.refresh_field(‘ng_weight’); });
Replace your code With @Shah_Kalpit ’s code
Shah_Kalpit:
frappe.ui.form.on(“Work Order Item”,“required_qty”, function(frm){ var required_quantity=0; for(var i=0;i<cur_frm.doc.work_order_item.length;i++){ required_quantity+=parseFloat(cur_frm.doc.work_order_item[i].required_qty); } cur_frm.doc.ng_weight=parseFloat(required_quantity); cur_frm.refresh_fields(“ng_weight”); });
Hello, thank you for respond me.
I already replace it, but still not working.
I also put the custom script in the Work Order doctype.
@cloudeater Refer this post,
This may help:
//The following three scripts calculates the rate/amount based on quantity.
frappe.ui.form.on("Material Request Item", {
rate: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, 'amount', (d.qty * d.rate));
var total = 0;
frm.doc.items.forEach(function(d) {
total += d.amount;
});
frm.set_value('total_amount', total);
},
qty: function(frm, cdt, cdn) {
var …
1 Like