Hi All,
Pretty new to coding side, so have been looking around through forums pulling info.
Have been trying to put together a custom script to pull the custom field value (cubic_volume) from the item master for each specific item in the Packing Slip, and populate the Packing Slip Item field (cubic_volume) with that value. I have placed the script in Packing Slip custom script as read this is where it needs to go for child tables however no luck. Screenshot shows what is needed to be pulled across visually.
Any assistance with the code would be appreciated. Thanks
// Set cubic volume of item
frappe.ui.form.on("Packing Slip Item", "onload", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
for(var i in d) {
res = frappe.db.get_value("Item", d.item_code[i], ["cubic_volume"])
frm.set_value("d.cubic_volume",res)
}
});
Thanks for your response @makarand_b.
Tried a few variations (including cur_frm.add_fetch) however still not working with the below. I am wondering whether the for(var… may be the issue - does that seem correct context to apply to each row in table?
// Set cubic volume of item frappe.ui.form.on("Packing Slip Item", "onload", function(frm, cdt, cdn) { var d = locals[cdt][cdn]; for(var i in d) { frm.add_fetch("item_code", "cubic_volume", "cubic_volume") } });
The loop just updates the field multiple times; it does not help you in this context.
// Set cubic volume of item
frappe.ui.form.on("Packing Slip Item", "onload", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
for(var i in d) {
alert(i);
frm.add_fetch("item_code", "cubic_volume", "cubic_volume")
}
});
To understand, look at the alert function which will display all the fields on the form due to the loop.
Thanks @Eddie - will take another look, been busy with other items so put this on back burner… will look through existing code to see if I can put together