Hi, I have used Field(s) changed validator "attachment" but it is not making the field mandatory.
Then I have used script validator using condition below:
import com.atlassian.jira.component.ComponentAccessor
ComponentAccessor.attachmentManager.getAttachments(issue).size() = 0
This is not letting me submitting the form as the error message is displaying.
Is there any solution?
Thanks
Swarna
Hello @Swarna Radha
You can create custom script validator to achieve this.
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
import com.opensymphony.workflow.InvalidInputException
def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)
def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)
if (formToken) {
def tempWebAttachments = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)
tempWebAttachments.each { TemporaryWebAttachment it ->
log.error("Uploaded attachment name: ${it.filename}")
}
if(!tempWebAttachments){
throw new InvalidInputException(IssueFieldConstants.ATTACHMENT,
"You must upload attachment")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Mark Markov Works very nice. Very nice, indeed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mark,
Is there a way to make attachments filed mandatory based on custom field value?
for example, I want to make attachments mandatory only when field value = x
we are using jira server with script runner plugin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @viswa.reddy, Do you have the solution for your case? I need exactly the same. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Swarna Radha
Please use the following instead with simple script validator:
import com.atlassian.jira.component.ComponentAccessor
ComponentAccessor.attachmentManager.getAttachments(issue).size() >= 1
I hope this will help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any option to check if the no of attachments are 4 in number.
and for a specific transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The solution for the SimpelScriptValidator ends every time in a NullPointerException.
The solution above for the custom script validator works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This checks, if a issue has something attached. But during the transition the attachment is not yet been attached. This is the reason why the TemporaryWebAttachmentManager has to be used.
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.