HI there-
I’m struggling on understanding how to link fields.
Scenario:
I have purchase cost on my Item doctype.
I want the purchase cost to show on my purchase order item child table.
So, I create a LINK field. How do I get it to pull the purchase cost from the item? I have tried everything and want to pull my hair out! 
Thanks in advance!
Relax, don’t pull your hair and a bald head is a workaround :D,
firstly you can change your purchase_cost fieldtype in the Purchase Order Item child table as Ready Only and in Options “if your frappe version less than 11” put item_code.purchase_cost “assume the purchase_cost is the name of the purchase cost custom field in item doctype”.
if you are in frappe version 11 put item_code.purchase_cost in Fetch From rather than Options,
if you don’t want the purchase_cost as Ready Only you have to create a custom script for Purchase Order doctype to fetch the purchase cost from item doctype and here is how to achieve that:
cur_frm.cscript.item_code = function(doc,cdt,cdn){
var d = locals[cdt][cdn];
frappe.call({
method: "frappe.client.get_value",
args:{
doctype: "Item",
fieldname: "purchase_cost",
filters:{
name: d.item_code
}
},
callback: function(data) {
if(data.message){
frappe.model.set_value(cdt, cdn, "purchase_cost", data.message.purchase_cost);
}
}
});
}
1 Like
Haha… yes, bald head might not be so good on me. 
Thanks for helping me out here. I am using ERPNext Cloud so I don’t even know what version I’m on. 
I was able to get this working setting up the read only field on purchase order item and then using this on purchase order custom script:
cur_frm.add_fetch(‘item_code’,‘purchase_cost’,‘purchase_cost’)
It doesn’t look like currency and doesn’t seem to calculate in the total so I’m going to have to play with that some more to get it the way I want but I really appreciate your help and this script. I did try it but couldn’t ever get it to pull the data in for me.
Thanks again!
You will find that under Help → About