ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How to fetch data from a template and display


#1

I have added a new custom field called (Units of Measurement )in the Quality Inspection Parameter
then >
created the same field,( same name) in Quality Inspection Readings .
Then >
I went to Quality Inspection and created NEW and selected Quality Inspection Template . The custom field from the table does not populate.
Only the already existing fields such as Specification & Acceptance Criteria are being fetched.
I have read the instructions and it says keep the custom field as data which i did


#2

Use in custom_script

add_fetch(link_fieldname, source_fieldname, target_fieldname)

Example:

cur_frm.add_fetch(‘customer’,‘vat_id’,‘vat_id’)


#3

thanks for your reply!
can you give me a better example. If my created field name is “Unit” inside "Quality Inspection Template Parameters and in the Doctype it is saying using Module “Stock”

Do i do it like this

cur_frm.add_fetch(‘Quality Inspection Template Parameters’,‘Unit’,‘Unit’) ?

Like this

Thank you for your help!


#4

another thing, the Quality inspection template is Linked to “Quality Inspection Template parameters " this has the custom fields. then Quality Inspection is linked to Quality Inspection Template Readers” Readers is linked to Quality Inspection Template.

So what do cur_frm.add_fetch(‘customer’,‘vat_id’,‘vat_id’)


#5

Hello @sealcoatings
First of all, why you are saying template? You are confusing us. Template term is used for html and pages.
It is better to use doctype, child doctype, document and child document (the table inside the document). Doctype is the form it self, example: Sales Invoice and Child Doctype is a doctype that can be inserted in another Doctype, example of it is Sales Invoice Items.
Regarding to Document: from each doctype, we will create documents. Example: SINV0001 and SINV0002 and so on.

Coming to your requirement, I will explain it for you as following:
cur_frm.add_fetch(‘field_name_of_type_link’, ‘source_field_name’, ‘destination_field_name’);

Where:
source_field_name is the name of the field in the doctype that you need to bring from it the data.
destination_field_name is the name of the field in the doctype that you need to place (or set) the data in it.

Regards
Bilal


#6

thanks for the update. Its my first time, its alittle confusing but nearly there.

The field in Doctype is Item Quality Inspection Parameter and the custom field is called Unit.
The Doctype is called Quality Inspection but inside it has a table called Quality Inspection Reading.
The Doctype Qualty Inspection Reading has the same field names Item Quality Inspection Parameter .
So when you goto Doctype Quaility inspection and select the template to populate the table .

So do i goto Custom Script , Select Quality Inspection Doctype

cur_frm.add_fetch(‘Item Quality Inspection Parameter’,‘unit’,‘unit’) ?


#7

Please answer me on the following:

  • What is the name of the source doctype and its child doctype that you need to fetch from it?
  • What is the name of the destination doctype and its child doctype that u need to set the data in it?
  • What custom fields u added and in which doctype?

Regards
Bilal


#8

THe field is called “Unit” inside "Item Quality Inspection Parameter " which is childdoc to “Quality Inspection Template”
THen in Quality Inspection , it has link to Doctype called “Quality Inspection Readings” which is table.
Inside Quality Inspection , you can select “Quality Inspection Template” to populate “Quality Inspection Readings” table.

You can see it in the default ERPNEXT 11

hope this makes sense

thank you so much for you help


#9

THe field is called “Unit” inside "Item Quality Inspection Parameter " which is childdoc to “Quality Inspection Template”
THen in Quality Inspection , it has link to Doctype called “Quality Inspection Readings” which is table.
Inside Quality Inspection , you can select “Quality Inspection Template” to populate “Quality Inspection Readings” table.

You can see it in the default ERPNEXT 11

hope this makes sense

thank you so much for you help


#10

OK, it will not work using cur_frm.add_fetch, you need to use frappe.call and you need to call python method which will return the needed values based on the selected template.

Regards
Bilal


#11

can you give me an example?

thank you!