Query builder operations

The query_builder operations can be used with any Object Type for the script. It returns a query that you can use as the query argument in helper.findIncidents(query).

Type query_builder. to access its operations.

Use query_builder to build queries. When you build a query, be aware of the following behavior.

  • The query_builder object has numerous match functions, including hasValue, hasNoValue, equals, notEquals, contains, notContains, isLessThan, isLessThanOrEquals, isGreaterThan, and isGreaterThanOrEquals. Each takes a field name as the first argument, as defined by the fields object.
  • The query_builder object has two sort functions, sortByAscending and sortByDescending. Each sort function also takes a field name as the first argument, as defined by the fields object. Sorts are applied in the order in which the sort functions are run.
  • The query_builder object has two control functions.
    • build(). Generates a query object that reflects the match and sort function calls that were made on query_builder, and can be used with helper.findIncidents.
    • reset(). Clears all matches and sorts so that a new query can be constructed.
  • When you create a query, the return value from all of the match condition and sort specification functions is the query_builder object itself. Therefore, calls can be chained together; as shown in the following example.
    query = query_builder.contains(fields.incident.name, 'foo').sortByAscending(fields.incident.id).build()
    It is equivalent to the following.
    query_builder.contains(fields.incident.name, "foo")
    query_builder.sortByAscending(fields.incident.id)
    query = query_builder.build()
Note: Broad queries that contain a many results can cause performance issues with the script, which can cause the script to exceed timeout limits and fail. For best results, make your query as specific as possible; for example, specify a date range in the query.