過濾表示式與過濾物件

過濾器表示式不能包含過濾器物件。這是非常重要的。如果你決定使用 Filter Expression 形成過濾器,則使用字串陣列陣列。以下語法錯誤

// WRONG!!!
var f1 = search.createFilter({
            name: 'mainline',
            operator: search.Operator.IS,
            values: 'T'
});

var f2 = search.createFilter({
            name: 'type',
            operator: search.Operator.ANYOF,
            values: ['VendBill','VendCred']
});

// here you will receive an error message
var s = search.create({
    type    : 'transaction',        
    filters : [ f1, 'and', f2 ] // f1,f2 are Filter Objects, instead of string arrays
});

相反,使用正確的

// CORRECT!!!
var f1 = ['mainline', search.Operator.IS, 'T'];

var f2 = ['type', search.Operator.ANYOF, ['VendBill','VendCred'] ];

var s = search.create({
    type    : 'transaction',        
    filters : [ f1, 'and', f2 ]
});

或者如果你想繼續使用 Filter Objects 方法,傳遞一組過濾器物件,並忘記運算子’AND’,‘OR’,‘NOT’。它將始終是 AND

// correct, but not useful
var f1 = search.createFilter({
            name: 'mainline',
            operator: search.Operator.IS,
            values: 'T'
});

var f2 = search.createFilter({
            name: 'type',
            operator: search.Operator.ANYOF,
            values: ['VendBill','VendCred']
});

var s = search.create({
    type    : 'transaction',        
    filters : [ f1, f2 ] // here you have array of Filter Objects,
                         // filtering only when all of them are TRUE
});