Snippets

Adaptavist Jira Cloud - Clone Issue Fields and Link Issue Script Console

Updated by Kristian Walker

File CloneIssueFieldsAndLink.groovy Modified

  • Ignore whitespace
  • Hide word diff
         .header('Content-Type', 'application/json')
         .asObject(Map)
 
-// validate that the source issue was returned correclty
-assert sourceIssue.status >= 200 && sourceIssue.status <= 300
+// validate that the source issue was returned correctly
+assert sourceIssue.status >= 200 && sourceIssue.status < 300
 
 def sourceIssueFields = sourceIssue.body.fields
 
         .asObject(Map)
 
 // validate that the clone issue was created correctly
-assert clonedIssue.status >= 200 && clonedIssue.status <= 300
+assert clonedIssue.status >= 200 && clonedIssue.status < 300
 
 // Create the issue link between both issues
 def link = post('/rest/api/2/issueLink')
         .asString()
 
 // validate that the issue link created correctly
-assert link.status >= 200 && link.status <= 300
+assert link.status >= 200 && link.status < 300
 
 return "The ${sourceIssue.body.key} source issue was cloned to the ${clonedIssue.body.key} issue and they have been linked as a clone."
Updated by Kristian Walker

File CloneIssueFieldsAndLink.groovy Modified

  • Ignore whitespace
  • Hide word diff
         .header('Content-Type', 'application/json')
         .body(
                 [
+                        // Add any extra fields to clone below
                         fields: [
                                 summary    : sourceIssueFields.summary,
                                 description: sourceIssueFields.description,
-                                assignee   : sourceIssueFields.assignee.accountId,
                                 project    : [
                                         key: sourceIssueFields.project.key
                                 ],
Updated by Kristian Walker

File CloneIssueFieldsAndLink.groovy Modified

  • Ignore whitespace
  • Hide word diff
 assert sourceIssue.status >= 200 && sourceIssue.status <= 300
 
 def sourceIssueFields = sourceIssue.body.fields
-                                
+
 def clonedIssue = post('/rest/api/2/issue')
         .header('Content-Type', 'application/json')
         .body(
                         fields: [
                                 summary    : sourceIssueFields.summary,
                                 description: sourceIssueFields.description,
-                                assignee: sourceIssueFields.assignee.accountId,
+                                assignee   : sourceIssueFields.assignee.accountId,
                                 project    : [
                                         key: sourceIssueFields.project.key
                                 ],
                                 ]
                         ]
                 ])
-       .asObject(Map)
+        .asObject(Map)
 
 // validate that the clone issue was created correctly
 assert clonedIssue.status >= 200 && clonedIssue.status <= 300
 // Create the issue link between both issues
 def link = 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' at
-        inwardIssue: [ key: clonedIssue.body.key ]  // You'll need to specify an issue ID or key here
-])
+        .body([
+                type        : [name: "Cloners"],
+                outwardIssue: [id: sourceIssue.body.id],  // This is the issue that the link 'starts' at
+                inwardIssue : [key: clonedIssue.body.key]  // You'll need to specify an issue ID or key here
+        ])
         .asString()
 
 // validate that the issue link created correctly
Updated by Kristian Walker

File CloneIssueFieldsAndLink.groovy Modified

  • Ignore whitespace
  • Hide word diff
 // validate that the issue link created correctly
 assert link.status >= 200 && link.status <= 300
 
-return "The ${sourceIssue.body.key} source issue was cloned to the ${clonedIssue.body.key} issue and they have been linked as a clone. "
+return "The ${sourceIssue.body.key} source issue was cloned to the ${clonedIssue.body.key} issue and they have been linked as a clone."
Created by Kristian Walker

File CloneIssueFieldsAndLink.groovy Added

  • Ignore whitespace
  • Hide word diff
+/*
+* 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." 
+*/
+
+def issueKey = 'IssueKeyHere'
+
+def sourceIssue = get('/rest/api/2/issue/' + issueKey)
+        .header('Content-Type', 'application/json')
+        .asObject(Map)
+
+// validate that the source issue was returned correclty
+assert sourceIssue.status >= 200 && sourceIssue.status <= 300
+
+def sourceIssueFields = sourceIssue.body.fields
+                                
+def clonedIssue = post('/rest/api/2/issue')
+        .header('Content-Type', 'application/json')
+        .body(
+                [
+                        fields: [
+                                summary    : sourceIssueFields.summary,
+                                description: sourceIssueFields.description,
+                                assignee: sourceIssueFields.assignee.accountId,
+                                project    : [
+                                        key: sourceIssueFields.project.key
+                                ],
+                                issuetype  : [
+                                        id: sourceIssueFields.issuetype.id
+                                ]
+                        ]
+                ])
+       .asObject(Map)
+
+// validate that the clone issue was created correctly
+assert clonedIssue.status >= 200 && clonedIssue.status <= 300
+
+// Create the issue link between both issues
+def link = 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' at
+        inwardIssue: [ key: clonedIssue.body.key ]  // You'll need to specify an issue ID or key here
+])
+        .asString()
+
+// validate that the issue link created correctly
+assert link.status >= 200 && link.status <= 300
+
+return "The ${sourceIssue.body.key} source issue was cloned to the ${clonedIssue.body.key} issue and they have been linked as a clone. "
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.