Snippets: search
Oktul Code Studio script snippets for searching work items with JQL, copied from the console and run by its tests.
These are the snippets the console’s Snippets dialog offers under Search. Each is TypeScript; in a .js script the console shows the same code with its types removed. Every one runs unchanged in Code Studio’s own tests. How the API they call behaves is in writing scripts and the script API reference.
Search with JQL, every page
Reads every work item a JQL query finds, 100 at a time, following nextPageToken. Ask only for the fields you use to keep each page small.
interface Page { issues: { key: string; fields: { summary: string } }[]; nextPageToken?: string;}
export default async function () { const keys: string[] = []; let nextPageToken: string | undefined; do { const page: Page = await jira.post('/rest/api/3/search/jql', { jql: 'project = DEMO AND statusCategory != Done ORDER BY created DESC', fields: ['summary'], maxResults: 100, nextPageToken, }); keys.push(...page.issues.map((issue) => issue.key)); nextPageToken = page.nextPageToken; } while (nextPageToken); log.info(`Found ${keys.length} work items`); return { count: keys.length };}Count what a JQL query finds
Asks Jira for an approximate count without reading a single work item.
export default async function () { const { count } = await jira.post<{ count: number }>('/rest/api/3/search/approximate-count', { jql: 'project = DEMO AND created >= -7d', }); return { count };}Related
A problem or a question? Write to support@oktul.com or open a request in the Help Center (opens in a new tab).