/** This example script console script shows how to clone fields from one issue to another and to link the two issues together as a clone. * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */defissueKey='IssueKeyHere'defsourceIssue=get('/rest/api/2/issue/'+issueKey).header('Content-Type','application/json').asObject(Map)// validate that the source issue was returned correctlyassertsourceIssue.status>=200&&sourceIssue.status<300defsourceIssueFields=sourceIssue.body.fieldsdefclonedIssue=post('/rest/api/2/issue').header('Content-Type','application/json').body([// Add any extra fields to clone belowfields:[summary:sourceIssueFields.summary,description:sourceIssueFields.description,project:[key:sourceIssueFields.project.key],issuetype:[id:sourceIssueFields.issuetype.id]]]).asObject(Map)// validate that the clone issue was created correctlyassertclonedIssue.status>=200&&clonedIssue.status<300// Create the issue link between both issuesdeflink=post('/rest/api/2/issueLink').header('Content-Type','application/json').body([type:[name:"Cloners"],outwardIssue:[id:sourceIssue.body.id],// This is the issue that the link 'starts' atinwardIssue:[key:clonedIssue.body.key]// You'll need to specify an issue ID or key here]).asString()// validate that the issue link created correctlyassertlink.status>=200&&link.status<300return"The ${sourceIssue.body.key} source issue was cloned to the ${clonedIssue.body.key} issue and they have been linked as a clone."
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.