Snippets

Adaptavist Copy attachment names in a cf

Created by Joaquin Fernandez

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+//Find and store the attachment names in a paragrahp custom field 
+def issueKey = 'NOT-1'
+
+def result = get('/rest/api/2/issue/' + issueKey)
+        .header('Content-Type', 'application/json')
+        .asObject(Map)
+        
+        
+def filenames = result.body.fields.attachment.filename.join(", ")
+
+        
+def result2 = put('/rest/api/2/issue/' + issueKey)
+        .header('Content-Type', 'application/json')
+        .body([
+        fields:[
+                customfield_10079: filenames
+        ]
+])
+        .asString()  
+        
+        
+if (result2.status >= 200 && result2.status<300){
+    return filenames
+} else {
+   return "Failed to update custom field with the attachment names"
+}
HTTPS SSH

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