Filtered dynamic link field

Any example to filter dynamic link field?
In documentation in the end it says “By default, the DocType link field will provide all the forms/docTypes for selection. If you wish this field to show certain specific docTypes in the search result, you will need to write Custom Script for it.”

But I cannot find any example that how to do this?

You can use this method: Set specific values in a field type Link - #2 by Nahuel_Nso

And for the filter use the field “name” and “in”. Then, in the values, put a list of the doctype names that you want.

I also have the same problem with dynamic link fields and creating a custom script.

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’);

Go to payment entry in accounting there it is automatically fetching the party name I worked on it so I know maybe its doing the same thing you are trying to do?