How to fetch value of link field in Sales Invoice Item

Hi,

I’m trying to automatically populate the Cost Center field in the Sales Invoice Item doc by fetching the value of a custom link field (also titled Cost Center) in the Sales Order doc. Add Fetch doesn’t seem to work in this case. Any suggestions will be greatly appreciated

Thanks

Hi , @wale Not sure if this could help you or not .

frappe.ui.form.on("Sales Invoice Item", "item_code", function(frm, cdt, cdn){
frappe.after_ajax(function() { 
frappe.call({
       "method": "frappe.client.get_value",
        args: {
		doctype: " Sales Order ",
		fieldname: "Cost Center",
		filters: {
		name:["=", frm.doc.sales_order]
			 }           			
	      },								
	      callback: function (data) {									
	      console.log(data);
              cur_frm.set_value("Cost Center", data.message.Cost Center);
				        }					
	     })

});

});

Thanks

1 Like

write a server side script using hooks.

1 Like

Hi @Muthu

Thanks for your suggestion but it doesn’t work either

@Basawaraj_Savalagi thanks but I’d rather not do any custom work on the server side if it can be avoided

Any idea why the regular Add Fetch function doesn’t work in this case?

Thanks

Hi @wale . The same script works for me , open the console and check for the errors, could you please ensure are you using the correct field_name in the above script .

Since this involved cost centre which has impact on your P&Lreports and other thing, its best to do server side customizations…

I have had issues when I wrote js code which involved fetching data from server and because of connectivity issues it didnt execute.

This is definately case for server side customization(unless you again you write js code to validate if your add_fetch or other methods have executed properly) .

Hi @Muthu

Yes, the field_name is correct. Are you using this script in a child table? The problem seems to be that the scripts don’t work in child tables. Pls confirm

Kind regards,

1 Like

Hi @wale. Yes add_fetch wont work for a child table , that is the reason I used the above script but this works fine for me .

Hi @Muthu

Are you using this on v8?

Thanks

Could you have a look at this method? Also, keep in mind you may need to refresh the form after, or save/validate and the info should populate. (Ignore the pet about it not working for long text)

Hi @superlack

Thanks for your input but link is missing. Kindly update pls

Kind regards,

My bad, up there now

No @wale . No I’m on v7 beta . Did you find the solution ?