Hello everyone,
I am trying to create a validation with script that forces the user to introduce at least three attachments in the creation of a request, I have created a custom script validation with the following 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 com.opensymphony.workflow.InvalidInputException
import webwork.action.ActionContext
def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)
def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)
if (formToken) {
def tempWebAttachments = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)
def attachmentSize = tempWebAttachments.size()
if(attachmentSize < 3) {
throw new InvalidInputException("Necesita adjuntar los siguientes ficheros: Operatoria, Plan de contingencia y Documentación adicional.")
}
}
The problem is that it does not work correctly since sometimes it allows me to create requests without adding any attachments or when I enter more than three attachments it skips the validation and does not allow me to create the issue, could you help me with this script please?
Regards.