Only 1 "set_query" working on my form

I’ve got 2 child tables on my customer form that I wish to control the linked query results using set_query.

The first child table in the code works fine, however the second one doesn’t work at all.

The odd thing is that when I use the code as a client script, it executes correctly. When I run the code from my custom app, linked with the hooks.py, only that first set_query is executed.

Any suggestions would be very appreciated.

frappe.ui.form.on("Customer", "refresh", function (frm) {
    frm.set_query("lease", "lease_summary", function () {

        for (let i in frm.doc.lease_summary) {

            return {
                "filters": {
                    "customer": cur_frm.doc.name

                }
            };
        }
    });

    frm.set_query("customer_id", "responsible_persons_list", function () {

        for (let i in frm.doc.responsible_persons_list) {
            return {
                filters: [
                    ['Customer', 'customer_group', 'in', 'Individual, Sole Trader'],
                ]
            };
        }
    });
});

Just giving this a bump. Any suggestions would be very much appreciated.

This looks like bug in JS code itself?

return immediately stops execution, so your for-loop isn’t doing anything, it returns on first item.

1 Like

ah. So simple :melting_face: thanks @ankush, you are correct.

Thanks for looking at this :raised_hands: