Validating Attachments Added this Transition using scriptrunner

ZubatyNos October 14, 2022

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

 

Screenshot 2022-10-14 150748.png

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:

Screenshot 2022-10-14 150721.png

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.

 

 

1 answer

0 votes
ZubatyNos October 17, 2022

This question was meant for the Jira product section, I apologize. I've already gotten an answer there:

https://community.atlassian.com/t5/Jira-questions/Validating-Attachments-Added-this-Transition-using-scriptrunner/qaq-p/2164380#M553345 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events