Query language
The query language ressembles the SQL language and allows powerful queries. A typical example would be:
{status} = 1 AND {reference}.StartsWith("2010") AND {deadline}.Matches("2018-10", ">=")
Fields are enclosed in curly brackets. To get a list of all available and queryable fields with ID, name and description, use this method.
Jump to a section:
Basic Features
The query language is very rich. The most important features are listed below:
General features | |
---|---|
= == | Compare field with a value. You can use both "=" and "==". These and other operators can be used with most field types.
CODE
Use double quotes with strings. Inside a string literal, a double quote is written as two consecutive double quotes:
CODE
|
>, < >=, <= | To compare numeric field values and dates.
CODE
|
!= <> | Not equal operators. Both have the same function. |
AND && | Boolean "and" to combine conditions.
CODE
|
OR || |
CODE
|
!= | Not equal.
CODE
|
( ) | Brackets can be used to combine multiple conditions:
CODE
|
! NOT | Negation:
CODE
|
x ? y : z | Evaluates y if x is true, evaluates z if x is false.
CODE
|
null | Literal to evaluate if a field is null or not:
CODE
|
Numbers | |
+ - * / | Numeric operators.
CODE
|
Decimals | Decimal fields use the optional '.' (dot) decimal point:
CODE
|
Strings | |
.StartsWith .EndsWith .Contains | Various operators to search string fields by prefix, suffix or infix. Use NOT to negate.
CODE
|
.Length | To query by string length:
CODE
|
Dates | You can use the DateTime object to compare dates. |
To compare a date:
CODE
Or with hours, minutes and seconds:
CODE
|
Recommended "Matches" keyword
We strongly recommend using the following construct for all your filtering requirements.
It takes away most of the complexity of properly formatting and evaluating different field types, including dates, multi-select custom fields, labels and advanced string searches.
Examples:
{myfield}.Matches("hello", "prefix")
{myfield}.Matches("2018-1-1", ">=")
{myfield}.Matches(10, ">=", 100, "<")
{myfield}.Matches("world") AND {mydate}.Matches("2018-1-1", ">=", "2018-1-2", "<")
...
String filtering
Basic
| Do an exact match:
CODE
|
Infix, Prefix, Suffix | Match types: exact, infix, prefix or suffix match:
CODE
|
Null values | Find null or not null values:
CODE
|
Any of
| Specify a list of values where at least one or all strings must match exactly:
CODE
This query is equivalent to a boolean OR on an exact match of each string. The above query is equivalent to: (({reference} = "o1") OR ({reference} = "o2") OR ({reference} = "o3"))
|
Number filtering
Basic | Exact numeric match:
CODE
Range match:
CODE
The operators can be any of: >, <, >=, <=, =, !=
|
Any of | This construct matches if the field matches any one of the pipe separated values:
CODE
|
Null values | Find null values with fields that are nullable:
CODE
|
Decimals filtering
Summary | You can use all the features also available with number filters. Please always use the "." (dot) character for the decimal point. The decimal point is optional. Examples:
CODE
|
Date filtering
Basic | Like with numeric fields, you can do different comparisons:
CODE
Important:
|
Date formats | Formats that are supported are:
Note: Partial date/times are automatically expanded. Example: "2018" is converted to 2018-01-01 00:00 |
Null values | Find null values with fields that are nullable:
CODE
|
Filter day or month | All deadlines on a day (UTC):
CODE
All deadlines in a month (UTC):
CODE
|
Date offsets | Sometimes it is easier to filter by a date offset. For example: Find jobs with a deadline of tomorrow. This can be expressed with "1d". More examples:
You can thus use one or more combinations of:
Deadline within +/- 6 hours:
CODE
All objects created since 1 year and 6 months:
CODE
|
Date offset filtering
Date offsets | Sometimes it is easier to filter by a date offset. For example: Find jobs with a deadline of tomorrow. This can be expressed with "1d". More examples:
Deadline within +/- 6 hours:
CODE
All objects created since 1 year and 6 months:
CODE
|
Units | You can thus use one or more combinations of:
You can prefix offset with "-" for dates into the past: -1y stands for one year ago. You can prefix with optional "+" for dates into the future: +1y (or 1y) stands for one year from now. |
Boolean filtering
Basic | Valid examples:
CODE
Permitted operators are: "=" and "!=".
|
Custom field multi select picklists
Multi-select pick list custom fields store selected values in a very specific format:
- "|Austria|France|Germany|"
Selected options are pipe delimited.
Find all options | Write like this:
CODE
|
Find any option | Write like this:
CODE
|
Comments: Whenever the field is a multi-select picklist, the system will automatically adjust the query. For the example above the query wil be:
{cffield}.Matches("o1|o2|o3", "anyof")
== translated to ==>
{cffield}.Contains("|o1|") OR {cffield}.Contains("|o2|") OR {cffield}.Contains("|o3|")
Labels count field
The labels count field returns the total labels assigned to an object such as a job or project.
It contains 2 properties:
- cnt: Total assigned labels.
- xp: Total explicitly set labels. This excludes labels that are configured to automatically show up on ALL objects with a default value.
The available query options are:
Filter for xp > 0 | This filter returns all objects that have at least one label that was explicitly assigned by a user.
CODE
|
Find for xp = 0 | This filter returns all objects with no label assigned by a user.
CODE
|
Label field
The available query options are:
Filter label options | Write like this:
CODE
You can also use the optional operator:
CODE
If a label is not shown by default, it can also have the "null" option:
CODE
|
Exclude label options | Write like this:
CODE
If a label is not shown by default, it can also have the "null" option:
CODE
|
Any label option | To filter for data where the label has any of the options:
CODE
|
Comments | When specifying a single value, the quotes are optional.
CODE
|
Query tree
When running queries the results may include a JSON representation of your query.
This happens whenever your query string is composed of just:
- .Matches() clauses
- "AND"
- "("
- ")"
Sample query:
/jobs/list/full
{ "query": '{created}.Matches("2018-03-13", ">=", "2018-03-15", "<") AND {segments}.Matches(100, ">")', "take": 10 }
Result includes:
"querytree": {
"and": [
{
"field": "created",
"params": [
{
"value": "2018-03-13T00:00:00Z",
"op": ">="
},
{
"value": "2018-03-15T00:00:00Z",
"op": "<"
}
]
},
{
"field": "segments",
"params": [
{
"value": 100,
"op": ">"
}
]
}
]
}
This is also helpful to see how dates and other values are interpreted.