Using Job Collection
5 min
Overview
JobCollection.LoadQuery allows you to load a filtered set of jobs by supplying a query condition that is evaluated in the same way as a SQL WHERE clause.
This method is commonly used in scripts and custom logic where job data needs to be queried programmatically.
How LoadQuery Works
The query string passed to LoadQuery represents the WHERE portion of a SQL query.
Any condition that is valid in a SQL WHERE clause can be used, provided the referenced fields exist on the Job object.
A maximum result count is supplied to limit the number of jobs returned.
Basic Syntax
JobCollection jobs = JobCollection.LoadQuery("<where clause>", <maxResults>);
- where clause defines the job filtering logic
- maxResults limits the number of jobs returned
Example: Date-based Query
The following example retrieves up to 1000 jobs with a status value of 3 that were submitted before a specific date:
JobCollection jobs = JobCollection.LoadQuery(
"Status = 3 and SubmitTime < '21 Apr 2019'",
1000
);
Common Use Cases
JobCollection.LoadQuery is typically used to:
- Retrieve historical jobs for reporting or processing
- Find jobs in a specific state or status
- Perform bulk operations against filtered job sets
Notes and Considerations
- Ensure date formats are valid for the underlying SQL engine
- Use result limits to avoid loading excessive numbers of jobs
- Test queries carefully before running them in production scripts