Hi everyone,
I'm trying to figure out how to use the Custom script scriptrunner post-function to look for attachements within the create screen, and after the issue is created, add the Jira ticket ID to the front of the attachement(s) name(s).
So far I have this:
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", issue.summary+it.filename)
attachment.store()
}
}
but I can't seem to get this to work. Can anyone help with this?
Thanks,
Mike
Hi all,
We figured out how to re-name / pre-append a Jira Ticket ID to all attachments that are added at the create step via the code below. Hope this helps someone else out.
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)
def issueID = issue.key
issue.getAttachments()?.each {
for(GenericValue attachment : delegator.findByField("FileAttachment", "id", it.id)) {
// if filename does not start with ticket key add it
if (!it.filename.startsWith(issueID)) {
attachment.setString("filename", "${issueID}_${it.filename}")
attachment.store()
}
}
}
Hi @Michael
From your description, it appears you are trying to rename the attachment name as they are added to the issue. Please confirm.
I am asking this so I can try to provide with a sample solution.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.