Query filters allow you to restrict which data from an internal database data store certain users will be able to access. They can be written to apply a filter expression to environment groups of users who query the data store and only allow those users to see certain records. When combined with user profile fields they can also be used to filter queried content at a user level, with no environment group assignment required. Examples of both types of query filter are shown below.
Using a filter expression and an environment group
As an example, consider a data set that contains a state field containing values from all 50 United States (IL, CA, OK, etc.). Also suppose that a system environment group named "Midwest" already exists, containing users who are only supposed to work with data from the Midwest U.S. region.
To construct a query filter that would only allow users in the Midwest environment group to see data from Midwest states, we could write the following Filter Expression:
state = 'IL' || state = 'IA' || state = 'WI'
We would then need to select the Midwest environment group as the environment group to apply this query filter to. By default, this query filter would then only allow users in the Midwest environment group to see data from IL, IA, and WI. Importantly, users not in the Midwest environment group would not see anything.
In the section above it is noted that once a query filter with an environment group assignment is applied, the default behavior is that users who are not part of that environment group will not see any data when they query the data store. Selecting Allow user to view all data when there are query filters but no matching query filter is found for a user will reverse this behavior, allowing users who are not part of the Query Filter's environment group to see all data in the data store.
Using a filter expression with user profile fields
As an alternative to applying query filters at an environment group level, query filters can be combined with user profile fields to apply restrictions at an individual user level.
As an example, consider a scenario where the following user profile fields have already been set up on the following user accounts:
User account |
Profile field name |
Profile field values |
---|---|---|
Bob |
state |
IL,MA |
Jane |
state |
CA |
In this scenario, a query filter with the following filter expression could be used:
dataStoreStateField = PROFILE_FIELD('state')
Here, state
refers to the profile field name set on the user account and dataStoreStateField
refers to a state field in the data store containing values from all 50 U.S. states. When a user queries the data store, the query filter will then only show them records where one of their profile field values matches the dataStoreStateField
value. With this type of set up, no environment group assignment is required.
Using multiple query filters
When multiple query filters are applied, the query filters are treated in an OR-like fashion. That is, each query filter is considered independently.
For example, if you had the following expressions being used as query filters:
1. field1 > 0
2. field2 < 100
Values such as -1 or 101 would both make it through the query filters.
To get an AND effect, you would need to combine these expressions into a single query filter.