Validate Attachment on transition screen using script runner

Hi I am trying to add a validator on a screen so that during a transition if they haven't uploaded a specific file it will show an error.

I use the following code in a Script Runner simple script validator but as I understand it the validator runs before the file is uploaded.

attachmentManager.getAttachments(issue).any{it.filename.toLowerCase().trim().startsWith('Form')}

That behaviour makes sens however I wondered if you can think of another way to validate an attachment on the screen.

For now I will probably have to ask the user to cancel their screen and transition after uploading the attachment.

2 answers

This widget could not be displayed.

Validating attachments and links added this transition does not seem to be possible using the JIRA API... short of examining the HttpRequest, which is a bit hacky and doesn't work with REST. If you look for an answer on how to validate that a link has been created, you can use the same technique.

Ok thanks Jamie - I will look for link validation examples. Thank you

This widget could not be displayed.

Hi Jamie, Angelos and future searchers,

Thanks to JIRA Suite Utilities's open source code, following trick is available to check attaches on transition: github/atlassian/jira-suite-utilities/.../FieldsRequiredValidator.java (Atlassian's fork) - search "IssueFieldConstants.ATTACHMENT" on the page.

Following imports will be required to compile code fragment for attachments check:

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueFieldConstants

I've tested this trick on JIRA 6.4 and it works fine.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

268 views 5 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you