I found an example for a cusrom script somewhere which I think fetches data from a source field to a target field. I assume the target field ideally would be ‘read only’
// cur_frm.add_fetch(link_field, source_fieldname, target_fieldname);
// cur_frm.add_fetch(“customer”, “local_tax_no”, “local_tax_no”);
I am a bit confused about the VARIABLE ‘link_field’ which is translated into “customer”. Customer (I think) is not a field but the name af the doctype from which the data is being fetched though. Isn’t that so?
If ‘yes’, shouldn’t the VARIABLE be ‘doctype’ instead of ‘link_field’?
Would it be possible to fetch values from 2 sources into 1 target?
for example you want to fetch customer_series and customer_name into a new field together
“CUST-00001 Revolver Co., Ltd.” would be what you get into the new field (so there is a space after the naming series even)
Hi @vrms the link_field is the name of a field on target doctype which is a link field to source doctype
In the above example customer is the link field to the customer doctype
as far as your second question is concern you have to write a custom script for performing the task it is not possible using add_fetch function
thanks for the feedback. I still can’t quite wrap my head around that yet though.
Can you explain how
link_field is different from
target_fieldname then? Also, (as far as I know) there is no field nowhere thats called
customer, only a doctype
Also, how would the system know in which
doctype to look for
Hi @vrms Sorry for the late reply link field is the field on a target doctype which is of type Link and which refers to a doctype in case of your example “customer” is a field which refers to a doctype (let’s say Customer Doctype) and which is on the target doctype.
local_tax_number is a field on Customer doctype which can be of type data or int.
Now if you want to fetch the value of local_tax_no. on another doctype for that you create a field on a target doctype and the name of the field is again local_tax_no.well it is not necessary that the both of the fields must have same name you can give any name to the target field.
Now about your second question.A link field represents only a single doctype at a time i.e in your example the field customer represents the customer doctype here because it is a link field to the customer doctype so the system comes to know that it has to fetch a value from a doctype referred by the link field name and the value to be fetched is from the field _source_fieldname and fetch it to the _target_fieldname which is present on the current doctype