Fetch data from supplier doc based on supplier chosen in invoice

Hello,

I need the purchase invoice to fetch data from the supplier profile once the supplier is selected in the purchase invoice. How can I do this? Add fetch isn’t working.

thanks,
Sofia

Can you share the code you’ve tried?

I got this code from the manual and used it in custom script:

cur_frm.add_fetch(link_fieldname, source_fieldname, target_fieldname)

Right, can you share the code that you tried in your custom script that didn’t work, so that we can give you advice on how to implement it?

I tried both of these and neither worked:

// cur_frm.add_fetch(supplier_name, nit, supplier_nit);
// cur_frm.add_fetch(supplier, nit, supplier_nit);

There is a field in the supplier profile called “nit,” I want to fetch it to the field called “supplier_nit” in the purchase invoice. In the first line of code I tried to refer to the supplier selected in the purchase invoice. In the second line I tried to refer to the supplier document.

thanks,
Sofia

I am assuming you didn’t have the “//” in front of the script? That is used to comment out the code and will prevent it from being registered.

I added the “//” and removed it and it doesn’t work in either case . When I used the same code to pull a field from the related purchase order the code worked but it won’t work for the supplier info.

worked
cur_frm.add_fetch(purchase_order, tracking_number, tracking_number);

didn’t work

cur_frm.add_fetch(supplier_name, nit, supplier_nit);
cur_frm.add_fetch(supplier, nit, supplier_nit);

Hey @sofia,

Try frappe.ui.form.on(cur_frm.doctype, “field_name”, function(frm, cdt, cdn) {

      // Your Code

})