Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

7 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.

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.

Like Zakhar likes this
Zakhar I'm New Here Sep 01, 2022

Hi @viswa_reddy, Do you have the solution for your case? I need exactly the same. Thank you! 

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