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.
Hi @Pedro J. Acosta
I tried your code with a simpled scripted validator, but it didn't run.
Then I tried it with a custom script validator, and it worked fine.
When you go to the transition validators screen, it shows you if your validator ran or not.
If it is running, you can add a log.warn attachmentSize , just to see what value is logging.
Hello Gustavo,
Thank you very much for your help and I am very sorry that it took so long to respond, I have tried both with a simple script and with a custom one and it fails me in both, anyway it is no longer necessary because my client no longer needs this restriction.
Regards.
P.D.: I'm Pedro, but I made a mistake when writing the comment, sorry for the confusion.
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.