Task References

On this page:

SearchJobs

Purpose

The SearchJobs task is used to query all jobs and return a filtered list of search results that match the query options that were specified. You can filter your search results by the number of jobs you have, even down to a particular field within a job.

Potential Use Case

Let's say you have an extensive list of jobs in a running state and you want to find a particular job (or collection of jobs) in your automation. You can use the SearchJobs task to query the workflow (automation) using any number of query options. For example, you can query an automation by job field id.

Properties

Input and output parameters are shown below.

Incoming Type Description
options object Available options in the SearchJobs task include: expand, fields, query, local, limit, skip, sort. See the Options table below for additional detail.


Outgoing Type Description
job object Search results that return from the query.


Options

Definitions for the various input options available in the SearchJobs task are summarized below.

Option Type Definition
expand array Sets a list of fields to get expanded data from. Generally these fields are "created_by", "user" or "owner".
fields object A filter specifying which fields are returned from the search query. The filter value is set to 1 (will return the field) or 0 (exclude the field from the results).
query object A MongoDB query object (field name/value pair).
local boolean Set to run the search query on a local IAP server.
limit number Specifies a limit on the maximum number of results returned in the search query. Default limit is 25.
skip number The number of data documents skipped in the search query before returning data. When 0, no documents are skipped. Useful for pagination.
sort object Set to sort the data that returns from the search query. If multiple fields return, results will sort from the first field and then the last field. You can specify -1 (descending sort order) or 1 ( ascending sort order).


Example 1

In the first example that's provided, no specific job is defined in the Reference variable.

searchJobs Static

The query returns a list that shows all the jobs in the workflow. By default, only the first 25 jobs (out of 200 available) were displayed in the Task History of Job Manager since no Reference Variable was specified.

searchJobs Static Results

Example 2

In the second example, the Reference variable to search for is the "_id" field and the search scope has been limited to 5 jobs.

searchJobs id

The input options used in the Reference Variable for this example are:

{
    "query": {
        "status": "complete"
    },
    "fields": {
        "_id": 1
    },
    "limit": 5,
    "page": {
        "skip": 0
    },
    "sort": {
        "name": -1
    }
}

The result will be limited to showing the "_id" field from the first 5 jobs searched. You can verify this by scrolling through the "results" displayed under the Outgoing tab in Task History.

searchJobs id Result

Note: The default limit, if no limit is chosen, is 25 out of 200 jobs shown per page. You can use the skip option to skip over a bulk number of jobs and move the search to the next page of results.