Hello All!
I am trying to add an attachment (PDF file) to a ticket upon ticket creation. I have engaged the post function "custom script post-function" with the following code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
def attachmentManager = ComponentAccessor.getAttachmentManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.loggedInUser
String pathToFile = "/var/atlassian/application-data/jira/"
String fileName = "ACP620.pdf"
String pathAndFile = pathToFile+fileName
def bean = new CreateAttachmentParamsBean.Builder()
.file(new File(pathAndFile))
.filename(fileName)
.contentType("text/txt")
.author(user)
.issue(issue)
.copySourceFile(true)//you must do this otherwise it deletes the source file from the file system
.build()
attachmentManager.createAttachment(bean)
I am getting the "No such file exists" error. Can someone advise on the correct way to do this?