Create fetch from Dynamic Field

On the Contract doctype under CRM, there is a “party_type” select option field if customer, supplier or employee. This is linked to a “party_name” dynamic link to select based on the “party_type”.

However, the complete name is not visible on the doctype so I create a data field “Full name” to appear the full name of supplier, customer or employee that was selected on the dynamic link.

How can I get the full name value since the fetch from is not applicable for dynamic links as per erpnext support.

I tried the if else custom script but still it did not work. Below is the script.

frappe.ui.form.on(“Contract”, {
onload(frm) {
if(frm.doc.party_type == “Customer”) {
cur_frm.add_fetch(‘party_name’, ‘customer_name’, ‘full_name’);
} else if(frm.doc.party_type == “Supplier”) {
cur_frm.add_fetch(‘party_name’, ‘supplier_name’, ‘full_name’);
} else if(frm.doc.party_type == “Employee”) {
cur_frm.add_fetch(‘party_name’, ‘employee_name’, ‘full_name’);
}
}
})