I attempted the same feat as @ninjas005
I placed this code in Custom script for doctype
My particular case:
Source DocType: Customer
Source field is a custom field with following options:
This field contains data, and can also be seen as column header in Report for each “Customer”, so one can select it as a column.
Target DocType: Sales Invoice
Desired behavior: When NEW Sales invoice is created, upon selection of Customer, a custom field in Sales Invoice labelled: TIN should be updated automatically with the data for the corresponding selected customer. The field can be read only. It should update automatically, each time a new customer is selected.
For a Sales Invoice created from a Sales Order or similar, when the NEW Sales Invoice is created, the same behavior is desired. And for each time a saved “Draft” Invoice is opened, the TIN should also load automatically.
SOLUTION FOUND: I managed to use the solution as described in the Custom Script Help when entering Setup>Custom Script>New. I used this version:
// fetch local_tax_no on selection of customer // cur_frm.add_fetch(link_field, source_fieldname, target_fieldname); cur_frm.add_fetch("customer", "tax_id", "tax_id");
Pending Problem: If created after several sales invoices have been created, it will only work with the NEW invoices, or by editing each one, reselecting Customer, and then the field will fill itself on its own. Once you save the invoice, the data is now saved with it. It would be great for it to be retroactive to previously created Sales Invoices (prior to new custom script)