Rename attachments in Jira using Groovy

While Atlassian is “GATHERING INTEREST” to implement file renaming feature in Jira, it is possible to rename attachments using Groovy.

If you use JMWE, Scriptrunner, etc.  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("attachment")?.each {
  for(GenericValue attachment : delegator.findByField("FileAttachment", "id", it.id)){ 
      attachment.setString("filename", "no_klienta_"+it.filename)
      attachment.store()
  } 
}