How to Automatically Set Default Filters and Update Value Field in Popup in Frappe

Hi everyone,

I’m working on a Frappe project where I need to automatically set default filters when a popup dialog opens. Specifically, I want to set the “Item Code (Batch No Details)” as the default filter field and set its value to a specified item code.

I have tried the following code to add and set the filter automatically:

javascript
Copy code
frappe.after_ajax(() => {
setTimeout(() => {
// Click to add the filter
$(“.add-filter”).click();

    // Set the filter field (for example, "Item Code (Batch No Details)")
    let fieldElement = $("[aria-owns='awesomplete_list_34']");
    fieldElement.val("Item Code (Batch No Details)").trigger("input");

    let options = [item_code];
    let htmlContent = '';
    options.forEach(function (option) {
        htmlContent += `<li>${option}</li>`;
    });

    // Set the HTML content in the element with the specified ID
    let listElement = $("[id='awesomplete_list_35']");
    if (listElement.length) {
        listElement.html(htmlContent);
    }

    let valueElement = $("[aria-owns='awesomplete_list_35']");
    valueElement.val(item_code).trigger("input");
    valueElement.trigger("change");
}, 500); // Initial timeout to allow dialog to render

});
While this code successfully adds the filter and sets the field to “Item Code (Batch No Details)”, the value field does not change to reflect the item list as expected. Manually selecting “Item Code” from the filter dropdown updates the value field to show the item list, but I need this to happen automatically.

Attached are screenshots for reference:

Can anyone provide guidance on how to ensure the value field updates correctly to show the item list when the filter is set programmatically?

Thanks in advance!

You can set the default value using the

    setters: {
        item_code: frm.doc.item_code,
    },

check this.

Thanks,
But in this work on the Parent table field, I have applied a filter in the child table data

click on the select batch no details then open this child table data in a popup so in this table, I set the filters

use the filter query on that like i have share code please use that code as reference

JS File :

get_query: function () {
						var filters = {
							item_code: item_code
						};
						return {
							query: "filter_query_path",
							filters: filters
						};
					}

Py File :

@frappe.whitelist()

@frappe.validate_and_sanitize_search_inputs

def filter_item_code_query(doctype, txt, searchfield, start, page_len, filters, as_dict, *args, **kwargs):
   # Write Your Code Logic
   return query
1 Like

When I open a popup, I want it to automatically set a filter. The current code I have sets values in the filter fields, but I need it to set an item code. The item code field is a type link, and it doesn’t refresh automatically, so it keeps showing the default batch number. I need the item code in the link field to update automatically when the popup opens. How can I achieve this?

Please provide a solution for setting the value in these third fields to update automatically in the filter when the popup is opened.

I Have attached the Video Link, So I Need This Type of Filters.

Any One ?