Filtered dropdown in Link Field

Hi,

I have Link field in my doctype which points to item doctye. When I click it I get a dropdown listing all items.

I need a list of items which item group is raw material,product. How can I filter that dropdown to have only item group is raw material,product.

Hi @Rahul7218 You can use a custom query to override the filter.

https://frappeframework.com/docs/user/en/guides/app-development/overriding-link-query-by-custom-script

Hope this link helps.

First check the documentation that provided by @Manjunath_Sajjan and also check the code in below reference:

I also have this kind of problem and this is my query.
frappe.ui.form.on(‘Material Request’, {
onload: function(frm) {
// Fetch and set parent item groups in custom_item_groups field
frappe.call({
method: “frappe.client.get_list”,
args: {
doctype: “Item Group”,
filters: {
‘is_group’: 1,
‘parent_item_group’: null // Fetch top-level item groups
},
fields: [“name”]
},
callback: function(r) {
if (r.message) {
let parent_item_groups = r.message.map(item => item.name);
console.log(“Parent item groups fetched:”, parent_item_groups);
frm.set_df_property(‘custom_item_groups’, ‘options’, parent_item_groups.join(‘\n’));
frm.refresh_field(‘custom_item_groups’);
}
}
});
},
custom_item_groups: function(frm) {
console.log(“Custom item group selected:”, frm.doc.custom_item_groups);
apply_item_code_filter(frm);
}
});

function apply_item_code_filter(frm) {
let item_group_filter = frm.doc.custom_item_groups;
console.log(“Applying item code filter based on custom item group:”, item_group_filter);

if (item_group_filter) {
    // Fetch and filter items based on the selected parent item group
    frappe.call({
        method: "frappe.client.get_list",
        args: {
            doctype: "Item",
            filters: {
                'item_group': item_group_filter
            },
            fields: ["item_code", "item_name"]
        },
        callback: function(r) {
            if (r.message) {
                let filtered_items = r.message;
                console.log("Filtered items fetched:", filtered_items);

                // Clear the existing items table
                frm.clear_table('items');

                // Add the filtered items to the items table
                filtered_items.forEach(item => {
                    let child = frm.add_child('items');
                    child.item_code = item.item_code;
                    child.item_name = item.item_name;
                });

                frm.refresh_field('items');
            } else {
                // If no items found, clear the items table
                frm.clear_table('items');
                frm.refresh_field('items');
            }
        }
    });
} else {
    // If no custom item group is selected, clear the items table
    frm.clear_table('items');
    frm.refresh_field('items');
}

}

I have a field called Item Group all item groups should be displayed in this field. But when I click food for example. The items in the table did not filter. Can you help me with this because I’m stuck in here. Thanks

Hi,
I want to add a search feature to the dropdown so that the dropdown values change based on the search input.
Please suggest me code

please explain more what you want

I need a search functionality for selecting a data type. When we enter some characters into the search field, it should call an API and fetch data based on the characters entered. We should then be able to select the data retrieved from the API.

Hi

The Link type of fields can be filtered by customizing highlighted filter button.

.

Further All Link Fields can be defined for search criteria by defining all those fields “Names” as highlighted below;

Hi, this is not my problem. I know how to specify the link type in DOCTYPE. My problem is that when a user type something, a dropdown should appear based on that input. The values in the dropdown should be fetched dynamically from the code base on a field event.

So you don’t want to filter the values of a link field, instead you want something similar to a dynamic link where you give an input and the drop-down gets generated dynamically based on the input?

yes, can you please suggest me code.