There is an issue type that I need validate the attachment before creation. The attachment must be a csv file. How can I validate the ".csv" string from name of attachment?
Hi,
Haven't tried it now, but it will work like below in the validator section:
import webwork.action.ActionContext def request = ActionContext.getRequest() if (request) { if (request.getParameter("filetoconvert") != null) { // Attachment(s) } }
Something you can try with below I found in my old repo.
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")
}
(above works for created issue)
@Piyush A (STR) thanks for answer! But the script still can't validate the attachment bc it still not exist. But I can build a javascript to validate and put it on the description of a field:
function att_loaded() {
attachment = document.getElementsByClassName("upload-progress-bar__file-name")[0]
if (attachment && !attachment.textContent.endsWith('csv')){
alert('Você precisa converter a planilha para CSV antes de prosseguir. Siga as etapas a seguir para realizar a conversão\n\n\
● Com a planilha aberta no Excel, clique em Arquivo > Salvar como\n\
● Abaixo do nome do arquivo, selecione o tipo "CSV (Separado por vírgulas)"\n\
● Clique em "Salvar" e tente anexar novamente o arquivo para prosseguir.')
}
}
button = document.getElementById("create-issue-submit")
button.addEventListener("mouseenter",att_loaded)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This would be good to verify the attachment while on the create screen. But it might not work as when creating via email or issue collector probably.
Above 1st should be in the create transition validator script that would eventually not accept the create issue.
But the Javascript looks great.
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.