
Building a filter
For this example, let's build a query that will only show records like this:
Incidents assigned to me that are not closed or cancelled, sorted by when they were last updated (oldest first).
First, let's break this down into components:
- Assigned to is me (the current user, whoever it may be)
- State is not either closed or cancelled
- Sort by updated (high-to-low)
You should be looking at two drop-down fields and one string input field, arranged in a row, like this:
Just like in math and programming, these three fields each represent a component of a condition criteria that looks something like <Field> <Operator> <Value>.
Click on the Keywords drop-down. In this drop-down, you'll see a list of fields on the Incident table. The first thing we want to do is filter based on to whom the incident is assigned, so type assigned to into the filter box at the top of the drop-down list, and then click on Assigned to.
The second field is the operator. This determines the type of comparison we're doing. In this case, we want records where the field is equal to a certain value, so for the operator, we might want to select is. However, if we try to enter a value into the value field on the right side of the condition, we'll see that it expects us to select a user from the Users table (since Assigned to is a Reference field that points to that table). We could select our own user account, but we want this filter to show tickets assigned to whatever user views it, so that won't work.
Luckily, for this situation, we have dynamic operators. On Reference fields, we can select the operator is (dynamic) (as opposed to just is), which gives us some dynamic options for the value. The first dynamic option is Me. This runs a script on the server, which replaces Me with whatever user is viewing the list.
These condition value fields accept JavaScript code, as long as it is preceded by JavaScript: If you were so inclined, or if you didn't have the is (dynamic) operator, you could use the GlideSystem API to get the sys_id of the current user for your query. You'd select is for the operator, and enter: javascript:gs.getUserID();.
So our first condition should look like this:
In order to add a second condition, we need to click the AND button. If we wanted to add a one or the other type of condition, we could use OR, but we want all of these conditions to match in order for a record to show up based on this filter.
After clicking AND, a new query condition line will appear. For the first part of this query line, select State from the drop-down. For the operator, choose is not one of. Finally, for the value(s), hold CTRL, and select both Closed, and Canceled. Your condition builder should not look pretty similar to this:
Finally, click on Run to filter the list of incidents. After running the filter, we then need to sort the list. There are two ways to sort a list:
- If the field you'd like to use to sort is displayed on the list view, you can simply click on that field header to sort by a to z (low to high). Clicking again sorts in the opposite direction. The down-sides to this method are that you can only sort on columns which display in your list view, and you can't do multi-level sorting.
- Alternately, after your query is in place, you can open the condition builder and click on Sort Filter. In the modal window that displays, you can select one or even multiple levels of sorting. For example, you could sort just by when the incident was updated, or you could sort by who the caller is, and sub-sort by how long ago the last update was.
For our purposes, we'll just need to sort by one field, and that field happens to be in our list view. To sort the incident table by when each ticket was last updated, we just have to click on the Updated column header once. That will sort it from low to high. Dates further in the past are considered lower than more recent ones, which are lower still than dates in the future.
Note that although you cannot do multi-level sorting just by clicking on the column headers, you can do something similar by grouping records together based on certain values. For example, if you wanted to see the results of the query we just built using the condition builder, grouped by Priority, but still sorted, within those groups, by the Updated date, you could simply right-click on the Priority header, and choose Group by Priority.