Bulk clone work items
Copy every work item a JQL query returns, up to 50 at a time, with a prefix on each summary.
Applies to: Script Master for Jira Β· Cloud
The script searches with your JQL, then creates one new work item per result with the fields you list. It runs as you, so your account must be able to see the work items and create work items in the target space.
Before you beginβ
- Jira permission: Jira admin, to open the Script Console. Your account also needs permission to create work items in the target space.
- App permission: an active Script Master license.
Run the scriptβ
- On the Script Console tab, paste the script below into the editor.
- Set the four settings at the top. See Settings.
- Select Run.
Result: Result shows an indented list with one entry per work item: the key of its copy, or the reason it wasn't copied.
// Settings
const jql = 'project = DEMO AND labels = template';
const cloneFields = [
'summary', 'issuetype', 'project', 'description', 'priority',
'labels', 'components', 'fixVersions', 'assignee',
// Add the custom fields your create screen requires, for example 'customfield_10010'
];
const targetSpaceKey = ''; // Leave empty to create each copy in the same space
const summaryPrefix = 'Copy of '; // Leave empty for no prefix
// Search: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/
const query = new URLSearchParams({
jql,
maxResults: '50',
fields: cloneFields.join(','),
});
const searchResponse = await requestJira(`/rest/api/3/search/jql?${query}`, {
headers: { Accept: 'application/json' },
});
if (!searchResponse.ok) throw new Error(`Search failed: ${searchResponse.status}`);
const { issues } = await searchResponse.json();
const output = [];
for (const item of issues) {
const copy = { fields: {} };
for (const field of cloneFields) {
if (item.fields[field] !== undefined && item.fields[field] !== null) {
copy.fields[field] = item.fields[field];
}
}
if (targetSpaceKey) copy.fields.project = { key: targetSpaceKey };
if (summaryPrefix) copy.fields.summary = `${summaryPrefix}${item.fields.summary}`;
// Create: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post
const response = await requestJira('/rest/api/3/issue', {
method: 'POST',
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
body: JSON.stringify(copy),
});
const data = await response.json();
output.push(response.status === 201
? `${item.key} copied as ${data.key}`
: `${item.key} not copied: ${JSON.stringify(data.errors ?? data.errorMessages)}`);
}
return output.length ? output : 'No work items match the JQL';
Settingsβ
| Setting | Description |
|---|---|
jql | The JQL query that selects the work items to copy. The script copies the first 50 results. |
cloneFields | The fields to copy. Include every field the target space's create screen requires. |
targetSpaceKey | The key of the space for the copies, for example DEMO. Leave it empty to copy into the same space. |
summaryPrefix | Text put before each copied summary. Leave it empty for none. |
note
A copy is a new work item: it has no comments, attachments, links or history. If the target space lacks a work type or version that a field refers to, Jira rejects that copy. Result then shows Jira's error for that work item.
Relatedβ
- Run a script: run a script in the Script Console.
- Script Console output: read the result and errors.
- Create a work item: create a single work item from scratch.