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 doc
https://community.atlassian.com/t5/Jira-questions/Scriptrunner-Require-Attachment-on-transition/qaq-p/850615
Previous post on requiring an attachment
https://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.IssueFieldConstants
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessor
import com.opensymphony.workflow.InvalidInputException
def attachmentDirectoryAccessor = ComponentAccessor.getComponent(FileSystemAttachmentDirectoryAccessor)
def temporaryAttachmentDirectory = attachmentDirectoryAccessor.getTemporaryAttachmentDirectory()
def mIssue = issue as MutableIssue
def attachmentNames = mIssue.getModifiedFields().get(IssueFieldConstants.ATTACHMENT)?.newValue
if(!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".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.