With a scriptrunner validator I can make the attachment required however I want to also limit the attachments to only one file. How can I get a count of attachments to use in the validator?
Scriptrunner dochttps://community.atlassian.com/t5/Jira-questions/Scriptrunner-Require-Attachment-on-transition/qaq-p/850615
Previous post on requiring an attachmenthttps://community.atlassian.com/t5/Jira-questions/Scriptrunner-Require-Attachment-on-transition/qaq-p/850615
Thanks!
Hi @Larry Peery
If you could share your current script, it would be easier for the community to suggest changes. But based on the https://community.atlassian.com/t5/Jira-questions/Scriptrunner-Require-Attachment-on-transition/qaq-p/850615 post, I will suggest you something like:
if (tempWebAttachments.size() > 1){ throw new InvalidInputException(IssueFieldConstants.ATTACHMENT, "You must upload only 1attachment")}
I hope it helps. If this answer helps solve the problem, please come back and mark this answer as solved to help other community members with the same challenge. If not, you are welcome to share your solution as well.
Cheers,
Alex
Alex,
Thanks for the reply. I am using the script posted by Neil Arrowsmith (Thanks Neil!) referenced above.
import com.atlassian.jira.issue.IssueFieldConstantsimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessorimport com.opensymphony.workflow.InvalidInputExceptiondef attachmentDirectoryAccessor = ComponentAccessor.getComponent(FileSystemAttachmentDirectoryAccessor)def temporaryAttachmentDirectory = attachmentDirectoryAccessor.getTemporaryAttachmentDirectory()def mIssue = issue as MutableIssuedef attachmentNames = mIssue.getModifiedFields().get(IssueFieldConstants.ATTACHMENT)?.newValueif(!attachmentNames) {invalidInputException = new InvalidInputException("You must add an attachment")}
I'm wanting to add something like...
else if(attachmentNames.count("temp") > 1) {invalidInputException = new InvalidInputException("Multiple attachments are not allowed. Only include 1 attachment.")}
however, even though I know the returned value of "attachmentNames" is "[temp3931897663971913341, temp5383865475765667504]" I cannot use ".count" against "attachmentNames".
I @Larry Peery
I might be missing something, but given that the attachmentNames variable has only the "temporary" attachment uploaded during the transition you might not need to count those with the name "temp".
Based on your input the attachmentNames variable seems to be an array, therefore I"m pretty sure to can try the method attachmentNames.size() > 1 to validate the number of files uploaded during the transition.
That worked. Thanks!
It looks like you're new here. Sign in or register to get started.