Multiple "OR" Filters in set query

I am trying to put multiple filters in my code where the use case is
→ First Filter should always be checked
→ There should be an OR statement for filter 2 as (field a: condition OR field b: condition OR field c: condition)
This is my code with single filter

frappe.ui.form.on("Doc", "category", function(frm) {
    cur_frm.set_query("scr", function() {
          return {
            "filters": {
                "category": cur_frm.doc.category,
                
                       }
                };   
    });
});

I tried filters as

"filters":[ ['category','=',cur_frm.doc.category  ],[['field a','=',condition] || 'field b', '=',condition ] ] ]

But I am getting error

ANY HELP

2 Likes

This is the error what I am getting

ValidationError: Filter must have 4 values (doctype, fieldname, operator, value): [[u'Scr', u'segment', u'Like', u'ABC']]

Doctype name is missing in your filters!
check this link:
https://frappe.io/docs/user/en/guides/app-development/overriding-link-query-by-custom-script

I suggest using Custom Method because of the flexibility of database query

thanks

Followed this way but still getting error

frappe.ui.form.on("Bank Reconciliation", "onload", function(frm){
    cur_frm.set_query("bank_account", function(){
        return {
            "filters": [
                ["Bank Account": "account_type", "=", "Bank"],
                            ["Bank Account": "group_or_ledger", "!=", "Group"]
            ]
        }
    });
});

Its giving error in custom script , the “Bank Account”: this if removed makes my code working but not able to apply filter as per my condition

You syntax is invalid:

Replace with:

["Bank Account", "account_type", "=", "Bank"],
["Bank Account", "group_or_ledger", "!=", "Group"]

Already tried, I am getting this

ValidationError: Filter must have 4 values (doctype, fieldname, operator, value): [[u'Scr', u'segment', u'=', u'ABC']]

Solved.

[Doctype name , field name, operator, value]

1 Like

Did this solution work?
[“Bank Account”, “account_type”, “=”, “Bank”],

1 Like

i guess so

"filters":[ ['category','=',cur_frm.doc.category  ],[['field a','=',condition] || 'field b', '=',condition ] ] ]

OR ( || ) is not supported, it throws

SyntaxError: invalid syntax

how does OR conditions work in frappe filters?

I dont see any documentation on it either

this works