How to Inspect the Attachment field for a specific file type
Asked by PJB:

Is there a way to inspect the "attachment" field within Jira? we are looking for a specific type of attachment file.


Answers:
author: Samuel Gatica
body: Hi [@Phil Burgard](/t5/user/viewprofilepage/user-id/5132083)

To inspect the Attachment field in Jira for a specific file type, you can use Jira Automation or a ScriptRunner (if available) to check the file types attached to an issue. Here's how you can approach it:

### 1. **Using Jira Automation** {#toc-hId-2147353524}

Jira Automation doesn't natively support inspecting attachments for specific file types directly, but you can work around this by using smart values and regular expressions.

**Example Automation Rule:**

* **Trigger:** Issue Created or Issue Updated (or another relevant trigger)
* **Condition:** Advanced Compare Condition or If/Else Condition
  * **First Value:** `{{issue.attachment.filename.match(".*\.pdf")}}`
  * **Condition:** "Does not equal"
  * **Second Value:** `""` (This means if a PDF is attached, the filename will not be empty)
* **Action:** Send an alert, comment, or perform any other action if a file with the specific extension (e.g., `.pdf`) is found.

*** ** * ** ***

### 2. **Using ScriptRunner (If Available)** {#toc-hId-339899061}

If you have ScriptRunner for Jira, you can write a Groovy script to inspect attachments and determine if a specific file type is present.

**Example Script:**

import com.atlassian.jira.component.ComponentAccessor  
import com.atlassian.jira.issue.Issue

def issueManager = ComponentAccessor.getIssueManager()  
def attachmentManager = ComponentAccessor.getAttachmentManager()

Issue issue = issueManager.getIssueObject("ISSUE-KEY") // Replace with your issue key  
def attachments = attachmentManager.getAttachments(issue)

def pdfFiles = attachments.findAll { it.filename.endsWith(".pdf") }

if (pdfFiles) {  
return "PDF file(s) found: ${pdfFiles\*.filename}"  
} else {  
return "No PDF files attached."  
}

You may also refer to this post for additional information: <https://community.atlassian.com/t5/Jira-questions/Use-Case-Verify-Attachment-Type-When-Transitioning/qaq-p/1631128>

Best regards

Sam


author: Maciej Dudziak _Forgappify_
body: Hi [@Phil Burgard](/t5/user/viewprofilepage/user-id/5132083)

If you are in a company-managed project it is possible validate attachments during create/ transitions with Jira expression-based validators.

I am from Forgappify, and we developed Jira Expression Validator, which is part of the [Workflow Building Blocks for Jira](https://marketplace.atlassian.com/apps/1233642/workflow-building-blocks-for-jira?hosting=cloud&tab=overview) app. Here is an example how to restrict .bmp, .exe, .bat, jam.dev file extensions:

```
issue.attachments.every(item => !item.filename.match('(bmp|exe|bat|jam.dev)$'))
```

It is also possible to inspect a mimeType, size, author, and even a create date of the attachments. I am leaving a link to our [expression library](https://docs.forgappify.com/workflow-building-blocks-for-jira/jira-administrator/jira-expressions-library#attachments)in case you are interested. If you can elaborate on what exactly you need, I can help you write the expression.

I hope it will help.

Cheers

comments: author: PJB
body: Thank you for answering the question.


Tags: cloud