Try ERPNext Buy Support Partners Foundation

Row's Custom Method Link Query not Working

I have a field in a child table whose query changes based on the other data within the form:

The query is set in JavaScript:

        frm.set_query("delivery_zone", "items", function() {
            console.log(fulfillment.forms.sales_order.delivery_zone_query);
            return {
                query: "myapp.mymodule.doctype.delivery_zone.delivery_zone.get_zone_query",
                filters: myobject_with_the_info_needed_from_form
            };
        });

I will note that this is called much after onload, which differs from the many examples.

My Custom Method query endpoint is not even being called:

22:50:54 web.1            | 10.0.2.2 - - [16/Sep/2020 22:50:54] "POST /api/method/frappe.desk.search.search_link HTTP/1.1" 200 -
22:51:00 web.1            | 10.0.2.2 - - [16/Sep/2020 22:51:00] "POST /api/method/frappe.desk.search.search_link HTTP/1.1" 200 -
22:51:01 web.1            | 10.0.2.2 - - [16/Sep/2020 22:51:01] "POST /api/method/frappe.desk.search.search_link HTTP/1.1" 200 -

Any ideas?

Note: running the SQL I have in my endpoint by hand only returns BYB-SL East as expected. However, there is no filtering done nor is the endpoint being called.

The custom query is being called, albeit not directly from the frontend. The function frappe.desk.search.search_link in turn calls a custom query whenever specified. You can add a print function to your query to test this.

I thought perhaps the module didn’t reload after the change, but my print statement inside my custom query method does not print to the dev console

I added a print statement to print the query given to frappe.desk.search.search_link and it’s None, meaning this isn’t working:

        frm.set_query("delivery_zone", "items", function() {
            return {
                query: "myapp.mymodule.fulfillment.doctype.delivery_zone.delivery_zone.get_zone_query",
                filters: theobject_with_the_filters
            };
        });

As I said, does this HAVE to be set onload? Or can it be set anytime after? This gets called when the fields that go into the filters are set.

There are quite a few instances where this is done on refresh instead of onload. I think set_query can be called anytime as long as you’re using the delivery_zone field after the set_query call. Are you maybe testing the field before this code gets triggered? Maybe try a console.log to see if this code gets triggered at all…

After further digging, I have found that while the query does not work when editing the field in the grid row, the query works fine in the larger, expanded view. Is there a way to fix it?

It also seems that the datepicker object for the Delivery Date fields are different between the row and this expanded view…currently investigating the difference.

Update: Filter Links Data in Child Table
This solution no longer works.

Solution:


This solution, as seen here:

seems that it must be done either before or during setup().

Thanks for reaching out @snv!