Set filter to link based on another field (In a child table)

When someone selects a “Marketplace”, the “Category” should filter for only the ones with this marketplace. Currently doing a client side script. Any better way to do this?

My child table:

The Category column is linked to this custom doctype:

My current non-working script: (I have gone as far as getting an action happening when the “Marketplace” field is changed inside the child table. It does not set the filter to the “Category” column)
image

Hi @plague69,

As per your scenario,

Similarly, we prepared a few pieces of logic. please check the video.

Client Script:

frappe.ui.form.on("Test DocType", {
  onload: function (frm) {
    frm.set_query("item_code", "test_child", function (doc, cdt, cdn) {
      let row = locals[cdt][cdn];
      return {
        "filters": {
          "item_group": row.item_group
        },
      };
    });
  },
});

Output:

I hope this helps.

Thank You!

2 Likes

@NCP absolute legend. Thank you. I was very stuck on how to get the row as well. This example explains many aspects!

How can we implement this onto a Dynamic Link. Looks like this does not work on Dynamic Link field-type.

Tested, it’s worked properly. please check it.

Well actually a Dynamic Link inside child table

Below is my script. I’m just trying to add a filter to the standard Payment Entry child table references

I have fixed the typo on *locals. Still not working

Paste the code, otherwise create a new thread for new issue, please!

Posting here itsel since I believe it falls under the same issue. But would create a new issue if required.

frappe.ui.form.on('Payment Entry', {
    onload: function (frm){
        frm.set_query("reference_name" ,"references", function (doc, cdt, cdn){
            let row = locals[cdt][cdn]
            return {
                filters: [
                    [row.reference_doctype, 'outstanding_amount', '>', 0]    
                ]
            };
        })
    }
})

will check

Hi @Nabyar,

It’s worked properly.

frappe.ui.form.on('Payment Entry', {
    refresh: function (frm){
        frm.set_query("reference_name" ,"references", function (doc, cdt, cdn){
            let row = locals[cdt][cdn];
            return {
                filters: [
                    [row.reference_doctype, 'docstatus', '=', 1],
                    [row.reference_doctype, 'company', '=', frm.doc.company],
                    [row.reference_doctype, 'customer', '=', frm.doc.party_name],
                    [row.reference_doctype, 'outstanding_amount', '>', 0]
                ]
            };
        });
    }
});

Output:

3 Likes