{"id":496,"date":"2019-12-19T09:07:54","date_gmt":"2019-12-19T07:07:54","guid":{"rendered":"https:\/\/drinkits.optimisti.lv\/?p=496"},"modified":"2019-12-19T09:07:54","modified_gmt":"2019-12-19T07:07:54","slug":"rename-attachments-in-jira-using-groovy","status":"publish","type":"post","link":"https:\/\/www.drinkits.lv\/en\/2019\/12\/19\/rename-attachments-in-jira-using-groovy\/","title":{"rendered":"Rename attachments in Jira using Groovy"},"content":{"rendered":"<p>While Atlassian is &#8220;<a href=\"https:\/\/jira.atlassian.com\/browse\/JRASERVER-25060\">GATHERING INTEREST<\/a>&#8221; to implement file renaming feature in Jira, it is possible to rename attachments using Groovy.<\/p>\n<p>If you use <a href=\"https:\/\/marketplace.atlassian.com\/apps\/292\/jira-misc-workflow-extensions-jmwe\">JMWE<\/a><a href=\"https:\/\/marketplace.atlassian.com\/apps\/6820\/scriptrunner-for-jira\">, Scriptrunner,<\/a> etc.\u00a0 in Jira, you can use following Groovy script:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import org.ofbiz.core.entity.GenericValue\nimport com.atlassian.jira.ofbiz.OfBizDelegator\nimport com.atlassian.jira.component.ComponentAccessor\nimport com.atlassian.jira.issue.attachment.Attachment\n\ndef attachmentManager = ComponentAccessor.getAttachmentManager()\n\nOfBizDelegator delegator = ComponentAccessor.getComponentOfType(OfBizDelegator.class)\nissue.get(\"attachment\")?.each {\n  for(GenericValue attachment : delegator.findByField(\"FileAttachment\", \"id\", it.id)){ \n      attachment.setString(\"filename\", \"no_klienta_\"+it.filename)\n      attachment.store()\n  } \n}<\/pre>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<a href=\"https:\/\/www.drinkits.lv\/en\/2019\/12\/19\/rename-attachments-in-jira-using-groovy\/\" rel=\"bookmark\" title=\"Permalink to Rename attachments in Jira using Groovy\"><p>While Atlassian is &#8220;GATHERING INTEREST&#8221; to implement file renaming feature in Jira, it is possible to rename attachments using Groovy. If you use JMWE, Scriptrunner, etc.\u00a0 in Jira, you can use following Groovy script: import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.ofbiz.OfBizDelegator import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.attachment.Attachment def attachmentManager = ComponentAccessor.getAttachmentManager() OfBizDelegator delegator = ComponentAccessor.getComponentOfType(OfBizDelegator.class) issue.get(&#8220;attachment&#8221;)?.each { for(GenericValue attachment : [&hellip;]<\/p>\n<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8],"tags":[15,38,42,43,47,49,53,90,91],"class_list":{"0":"post-496","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-skripti","7":"tag-attachment-rename","8":"tag-filen-rename","9":"tag-groovy","10":"tag-groovy-script","11":"tag-jira","12":"tag-jira-attachments","13":"tag-jmwe","14":"tag-script","15":"tag-scriptrunner","16":"h-entry","17":"hentry"},"_links":{"self":[{"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":0,"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.drinkits.lv\/en\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}