How to validate if a zip file is attached in the transition

I am using Scriptrunner to validate if a zip file is attached in the transition and find the code from  https://scriptrunner.adaptavist.com/5.0.3/jira/recipes/workflow/validators/validate-attachments-links-in-transition.html#_validating_attachments_added_this_transition  and set the code in the transition validator.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.attachment.TemporaryWebAttachment
import com.atlassian.jira.issue.attachment.TemporaryWebAttachmentManager
import webwork.action.ActionContext

def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)
def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)

if (formToken) {
def tempWebAttachments = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)
tempWebAttachments.each { TemporaryWebAttachment it ->
log.debug "Uploaded attachment name: ${it.filename}"
}
}

I upload the attachment in the transition form but it doesn't work in my JIRA 6.4.  It is checked that the "formToken" is null so it cannot flow in to "if" clause. Do I miss something or is there another way to do that?

Thanks in advanced.

 

1 answer

Hi, Chow,

 

you can try reading transient parameters map that is passed into your main Validator#validate method. 

User data that is updated in the transition dialog is usually kept there.

HI, Mikhail Kopylov,

 

Thanks. Is there any codes or link I can reference since I am not familiar with script?

 

Thanks.

May be smth like that: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/validators/simple-scripted-validators.html#_requiring_a_comment

 

I'm not familiar enough with script runner, I usually write my own plugin in Java.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,329 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot