Understanding Complex Filters

A filter can be as simple as Setting Equals 1, but more complex filters can be used in reports or for access control.

The built-in filter editor can be used to add conditions one at a time to a filter. These filter conditions are added using the AND or OR logical operators. By default, the AND operator has higher precedence than the OR operator. The filter editor does not allow the user to override the precedence (typically done by adding parenthesis).

Example

You have the following filter set up:The Conditions tab of a filter.

The filter in this example translates to: 

Entity Name starts with agl AND Entity Type = Computer OR Entity Type = Application AND Organization name = Acme

Since the AND operator has higher precedence than the OR operator, the above filter means: 

(Entity Name starts with agl AND Entity Type = Computer) OR (Entity Type = Application AND Organization name = Acme)

That is, the AND operations are performed first. 

If you want this filter to evaluate as:

(Entity Name starts with agl) AND (Entity Type = Computer OR Entity Type = Application) AND (Organization name = Acme)

There is no way to do this directly by using the filter editor. You must do this using the Matches Filter operator. To implement the above filter, you must build a Computer or Application Entities filter for the condition (Entity Type = Computer OR Entity Type = Application).

A Computer or Application Entities filter.

The original filter will use the Computer or Application Entities filter using the Matches Filter operator.

First, add the Name Equals agl condition. Use the Matches Filter operator to add the Computer or Application Entities filter. Note that a dummy entry must be selected in the first dropdown of the filter editor. In this case, Created By is selected, which is ignored by the server.Adding the Matches Filter operator.

Add Organization name Equals Acme. The filter will now look like this:The filter with the Matches Filter operator added.

Internally, the server surrounds the filter condition of the Matches Filter operator with parenthesis. So, this will translate to:

(Entity Name starts with agl)AND(Computer or Application Entities) AND (Organization name = Acme)

Which is effectively similar to the filter that you set out to construct:

(Entity Name starts with agl) AND (Entity Type = Computer OR Entity Type = Application) AND (Organization name = Acme)

This can be taken further by using Matches Filter operator within the filters used by another Matches Filter operator.