ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Multiple "OR" Filters in set query

custom_script

#1

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

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']]

#3

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


#4

thanks


#5

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


#6

You syntax is invalid:

Replace with:

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

#7

Already tried, I am getting this

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