Hi,
In Contract DocType, I would like to fetch the party full name based on selected party_type
and party_name
as below:
So, every time I change the Party Name (party_name
) field, I need to update the Party Full Name (party_full_name
) value with related party name, whether it fetch from Customer, Supplier or Employee depends on selected Party Type (party_type
).
Note: Party Full Name (
party_full_name
) is my custom read-only field
For that purpose, I try to add custom scripts on Contract Doctype as follow:
frappe.ui.form.on('Contract', {
party_name: function(frm) {
/* when party_type field is changed */
if (frm.doc.party_type == 'Customer') {
/* if party_type is 'Customer', fetch the field 'customer_name' of
the customer selected in 'party_name' and write it into the
current form's field 'party_full_name' */
frm.add_fetch('party_name', 'customer_name', 'party_full_name');
} else if (frm.doc.party_type == 'Supplier') {
/* if party_type is 'Supplier', fetch the field 'supplier_name' of
the supplier selected in 'party_name' and write it into the
current form's field 'party_full_name' */
frm.add_fetch('party_name', 'supplier_name', 'party_full_name');
} else if (frm.doc.party_type == 'Employee') {
/* if party_type is 'Employee', fetch the field 'full_name' of
the employee selected in 'party_name' and write it into the
current form's field 'party_full_name' */
frm.add_fetch('party_name', 'full_name', 'party_full_name');
}
},
})
With this script, I have two strange behaviors. First, every time I change the Party Name, the value of Party Full Name is only flash with the correct value and then goes blank as seen below:
Second, if I change the Party Type, I got following error, even I can confirm through the browser js debugger, that “if
” conditions are correctly executed.
Is there anything wrong with my custom script?
TIA,
Roy
ERPNext: v12.10.1 (version-12)
Frappe Framework: v12.8.0 (version-12)