How to validate if attachment exists on issue creation through service desk customer portal Edited


I am struggeling with a scripted workflow validation to check wether an attachment has been added on the create issue transition when using JIRA service desk´s customer portal.

EDIT: Actually I need to check if Attachments are added during issue creation ONLY if a custom fields has a specific value. Having this, simple solutions like the Field Required validation of JMWE plugin does not work in my case.

I found that the Script Runner plugin provides some very useful hints but the examples from adaptavist only seen to apply to the plain JIRA issue creation transition and not to the customer portal of the service desk.

I am running JIRA 7.4.2 with Service Desk 3.6.2 and Script Runner 5.0.14 and my validation script looks like this:

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 com.opensymphony.workflow.InvalidInputException
import webwork.action.ActionContext

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("de.agileworks.ValidateAttachments")

log.debug "VALIDATING 1"

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

log.debug "VALIDATING 2 => " + ActionContext.getRequest()

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

log.debug "VALIDATING 2.2"

def attachmentSize = tempWebAttachments.size()
log.debug "VALIDATING 2.3 => " + tempWebAttachments.size()

if(attachmentSize >= 1) {
log.debug "VALIDATING 2.3.1 => SUCCESS"
} else {
throw new InvalidInputException(IssueFieldConstants.ATTACHMENT,"SIZE: " + attachmentSize + " - You must add an screen shot at this transition!!!")

log.debug "VALIDATING 3"

As already mentioned it works fine when creating issues from within JIRA:

2017-08-18 11:50:55,331 DEBUG [agileworks.ValidateAttachments]: VALIDATING 1
2017-08-18 11:50:55,332 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2 => com.atlassian.plugin.servlet.PluginHttpRequestWrapper@625be7de
2017-08-18 11:50:55,332 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2.1
2017-08-18 11:50:55,332 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2.1.1
2017-08-18 11:50:55,333 DEBUG [agileworks.ValidateAttachments]: Uploaded attachment name: jira.png
2017-08-18 11:50:55,333 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2.2
2017-08-18 11:50:55,333 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2.3 => 1
2017-08-18 11:50:55,333 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2.3.1 => SUCCESS
2017-08-18 11:50:55,333 DEBUG [agileworks.ValidateAttachments]: VALIDATING 3

But when I try to do the same via the customer portal it does not:

2017-08-18 11:58:08,555 DEBUG [agileworks.ValidateAttachments]: VALIDATING 1
2017-08-18 11:58:08,555 DEBUG [agileworks.ValidateAttachments]: VALIDATING 2 => null
2017-08-18 11:58:08,555 DEBUG [agileworks.ValidateAttachments]: VALIDATING 3

As you can see the if-block covering the formToken will be skipped and it seems that the request is null or empty.

Did anyone encounter this situation already? Any hint or workaround would be very much appreciated.

Best Regards,


1 answer

You could try the JIRA Misc Workflow Extensions . There is a validator "Fields Required". You only add the field you want to validate and the error message if the validator fails. 


Hope I helped

BR, Athina

Hi Athina,

thank you for your reply. I have the JMWE plugin installed but the Fields Required validation only provides a check against a single criteria (e.g. Custom Field) but not against a combination of criterias like CF 1 eq "A" AND File Attached during transition as I require. Or do I missed something?

Regards, Christian

Hey again,

Yeah, you can add 2 Fields required conditions or more. 

I just had a look and yes you are right the Field Required validation can check multiple fields as required BUT NOT criterias like Attachment required if a CF have a specific value.

I have the same requirement and also would like a solution for this in Jira ServiceDesk.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

928 views 4 5
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