Hi everyone,
I'm using this groovy code to validate whether any of attachments added during workflow transition go beyond my allowed size. It works the first time, meaning that it correctly validates that there's an attachment with size that goes over the MAX_ATTACHMENT_SIZE limit, which can be seen on this screen
But when I then removed the file which goes over the limit (merged.pdf) and i try to transition again the validator still fails like this:
What I found out in the log is that the tempWebAttachments variable still holds the merged.pdf even though I removed it from the form. Is there anyway for tempWebAttachments to be up to date, even after I removed/added some attachments?
My validator code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.attachment.TemporaryWebAttachment
import com.atlassian.jira.issue.attachment.TemporaryWebAttachmentManager
import webwork.action.ActionContext
def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)
def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)
def MAX_ATTACHMENT_SIZE = 20971520
if (formToken) {
def tempWebAttachments = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)
tempWebAttachments.each { it ->
log.debug "Uploaded attachment name: ${it.filename}"
log.debug "Uploaded attachment filesize: ${it.size}"
}
return tempWebAttachments.every{it -> it.size <= MAX_ATTACHMENT_SIZE}
}
Regards.
This question was meant for the Jira product section, I apologize. I've already gotten an answer there:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.