paulinapomocka
9/30/2019 - 10:44 AM

WB filtering system

WB filtering system

Filtering

In addition to using _start and _limit to control the set of rows returned you can specify one or more filters. Filters are specified as arrays of parameters; each filter contains the following elements:

ParameterMnemonicUse
_ff[]Filter FieldThe name of the field, in the same format as ordering and grouping
_ft[]Filter TypeA comparison operator. See list below
_fc[]Filter CriteriaThe (value) data to match, UTF-8 encoded as everything else is. These can be comma-separated when ‘eq’ comparisons are used resulting in the equivalent of an ‘IN ()’ clause. Since you can specify multiple values for filter criteria separated by a comma, you must escape a comma by prefixing it with a backslash if you are looking for a string containing a comma.

In addition to the array of parameters you may also specify the matching mode through the _fm parameter. There are currently three possible value types:

ParameterValue type
_fm=andThe filter only includes rows that match all of the conditions specified by _ff[], _ft[] and _fc[]. This is also the default if _fm is not specified.
_fm=orThe filter includes any rows that match the conditions specified by _ff[], _ft[] and _fc[].
_fm= boolean expressionThe filter only includes rows that match the conditions specified by _ff[], _ft[] and _fc[] according to the boolean expression.

As a special case, if you only have a single filter, you can omit the square brackets from the filter parameters to pass _ff[], _ft[] and _fc[].

Alternate filter syntax

Rather than passing over _ff[], _ft[] and _fc[] separately you can combine them into a parameter called _filter_json which is a JSON representation of an array of filters, each filter being an array of three items: filter field, filter type, filter criteria:

_filter_json=[["name","ct","Hello World"],["object_ref","eq","CASE-1234"]]

Boolean expressions in filtering

The boolean expression for the _fm parameter can include any of:

  • NOT: boolean not (you can also use ! to mean NOT)
  • AND: boolean and
  • OR: boolean or
  • XOR: boolean exclusive or
  • parentheses for grouping
  • numbers referring to the filters

For example:

    (1 AND 2) OR 3  

would require that only rows that match filters 1 and 2, or that match filter 3 are returned.

Filtering Types

The list of Filtering Types will grow and is currently:

OperatorMeaningData types
bgBegins withstring
blankIs blankstring, integer, float, currency, date, time, datetime
ctContainsstring
eqOndate
eqAttime, datetime
eqEqualsboolean, string, integer, float, currency
falseIs falseboolean
geGreater than or equalinteger, float, currency
geOn or afterdate, time, datetime
ge_todayIs on or after todaydate, datetime
gt_todayAfter todaydate, datetime
gtGreater thaninteger, float, currency
gtAfterdate,time, datetime
leLess than or equalinteger, float, currency
leOn or beforedate, time, datetime
ltLess thaninteger, float, currency
ltBeforedate, time, datetime
le_todayIs on or before todaydate, datetime
lt_todayBefore todaydate, datetime
nbgDoes not begin withstring
nctDoes not containstring
neNot equalboolean, string, integer, float, currency
neNot ondate
neNot attime, datetime
not_blankIs not blankstring, integer, float, currency, date, time, datetime
todayIs todaydate, datetime
trueIs trueboolean

For the blank, not_blank, true, false, today, le_today, lt_today, ge_today and gt_today filtering types, fc[] should be present but is ignored. If you are testing boolean values using 'eq' or 'ne' then use the values 0 to represent false or 1 to represent true.

An example filter to filter all names that start with 'james':

      _ff[]=name&_ft[]=bg&_fc[]=james 

Further limiting the filter to employer 'ibm':

      _ff[]=name&_ft[]=bg&_fc[]=james&_ff[]=employer[name]&_fc[]=ct&_fc[]=ibm     

As you can see above since arrays of parameters are being passed it is important to specify them grouped sensibly together.