Hi Folks,
I need a script to get attachments for groovy to use in Create Validator script.
My purpose is to get all attachments which attached to the issue while creating in Customer Portal and check those attachment extensions (txt, sql, zip etc.) and prevent creation if any of those is not SQL file.
Before researching I want to use my existing code in Jira side to get attachments but it does not work in customer portal, it occurs "Java.NullException".
Then check the community to make sure if any topic is related to my issue, but I could not find what I exactly need.
Links I found before;
https://community.atlassian.com/t5/Marketplace-Apps-Integrations/How-to-validate-if-attachment-exists-on-issue-creation-through/qaq-p/627045
Guys please help me to find out how to get attachments during creation in validator and prevent in order to its file extension?
Thanks & Regards,
Burak
With this code you can get all the attachments of the issue, and with that list you can go through it and ask for the attribute of the file name and if they all have .SQL
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.IssueManager;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
def attachmentManager = ComponentAccessor.getAttachmentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
//Defino el logger
def logger = Logger.getLogger("com.attachment.groovy")
logger.setLevel(Level.INFO)
logger.info("Start script")
IssueManager issueManager = ComponentAccessor.getIssueManager()
def issueKey = issue.getKey()
List<Attachment> issueAttachments = attachmentManager.getAttachments(issue)
def validAttachment = issueAttachments.every { issueAttachment ->
issueAttachment.getFilename().contains("SQL")
}
Hi Juan,
It works on Jira itself but not in Jira Service Desk. Still getting error as "java.lang.NullPointerException" in
List<Attachment> issueAttachments = attachmentManager.getAttachments(issue)
Here are screenshots;
The code which I got from you; (It is in Create validator)
Here is the log which I got error when I create an issue from Service Desk Portal;
Thanks,
Burak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.