Validating Attachments/Links In Transitions

If a user adds attachments or links in a workflow transition, normally you cannot validate them because they're not accessible via the Jira API until the transition is complete. However, we have made it easy to access links or attachments by using extension methods on MutableIssue. Check out the following documentation for more information on accessing attachments and links during transition:

Validating attachments added

The following example details how to find properties of attachments added to this transition or on creation, for example the file name. 

The Attachments field must be on the transition screen to get attachments like this.

issue.attachmentsAddedInTransition.each { attachment ->
    log.debug("Uploaded attachment name: ${attachment.filename}")

Blocking files by extension

You can block files with certain extensions being added using the following script in conjunction with a Simple Scripted Validator.


def extensionsToBlock = ['exe', 'reg']

!issue.attachmentsAddedInTransition.any { attachment ->
    Files.getFileExtension(attachment.filename).toLowerCase() in extensionsToBlock

You cannot select the Attachments field as the field to show the error on. Leave the error field blank, and the error message will be shown at the top of the form.

Reading attachments added this transition

If you need to read the contents of newly-added attachments, for in-depth validation, you can get the data as follows:

issue.attachmentsAddedInTransition.each { attachment ->
    attachment.withInputStream { stream ->
        log.warn('File text: ' + stream.text)

Check out our HAPI documentation on Accessing attachments during transition for more information on how to access attachments during transition.

Validating links added this transition

The following example shows how to read links that have been added on the screen during the transition, and in this case, stops the action unless at least one blocks link has been added.

issue.allOutwardLinks*.issueLinkType.outward == ['blocks']

Check out our HAPI documentation on Accessing links in transition for more information on how to access links in transition.

Related content

On this page