Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to make attachment mandatory?

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?




2 answers

1 accepted

5 votes
Answer accepted

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}")
throw new InvalidInputException(IssueFieldConstants.ATTACHMENT,
"You must upload attachment")

Hi Mark 

It is working :)



Thank you @Mark Markov  Works very nice. Very nice, indeed.

2 votes
Mohamed Adel Community Leader Aug 22, 2018

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

@Mohamed Adel 


Any option to check if the no of attachments are 4 in number.


and for a specific transition.

The solution for the SimpelScriptValidator ends every time in a NullPointerException.

The solution above for the custom script validator works.

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.

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you