Fetch value from doctype to child table

Hi,
I’m newbie to ERPNext, so I would like to ask for help with this:

How to fetch value from my doctype record to child table on another doctype?

I mean, when I input Položka field I need to fetch it’s price to Cena položky from my custom doctype.
Like price for an item on Sales Invoice.

So if u have field XYZ and you want to it fetch value from doc type A to doctype B
So in customization when you create that field in fetch from you should write item_code.xyz

And you should code in sales invoice item doctype…let me know if it works for you

Thanks, I’ve done it through custom script:

1 Like

Which version of ERP are you working upon

I’m using v11.1.65.

1 Like

Ok thanks

1 Like

Hi I needed some input for your script

This script will fetch from selected doctype record to another doctype field.

frappe.ui.form.on("[PARENT_DOCTYPE_TARGET]", "refresh", function(frm) {	
	frappe.ui.form.on("[CHILD_TABLE_TARGET_DOCTYPE]", {
			"[CHILD_TABLE_LINK FIELD]": function(frm) {
			frm.add_fetch("[CHILD_TABLE_LINK FIELD]", "[SOURCE_CUSTOM_FIELD2]", "[TARGET_CUSTOM_FIELD2]");
		}
	});

});
1 Like

Where do you write this …did you write it in fetch from of the field that is to be created

No, just create a custom script on the doctype where you want to use it

Ok and instead of PARENT_DOCTYPE_TARGET do we have to write parent doctype name or write the script as it is

Parent Doc type Name (Name represents the route)

Fetch From uses a common link between this current doctype and the target doctype.

E.g: Transaction Doctype fetching from Master Doctype

Customer: {name, tax_id}
Sales Invoice: {customer {Link: Customer}, tax_id, items, …}

Get Customer field tax_id into Sales Invoice => Fetch From = customer.tax_id

E.g: Transaction Child Doctype fetching from Master Doctype

Item: {item_name, item_code, my_field}
Sales Invoice Item: {items {Link: Item}, item_code, my_field, uom, …}

  1. Get Item field my_field into Sales Invoice Item => Fetch From = item_code.my_field

  2. Reload

  3. Add new item to trigger the fetch