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

Hi,

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.setLevel(Level.DEBUG)

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,

Christian

4 answers

1 accepted

Hi @Christian Schlaefcke,

as mentioned within my first reply above, I've been able to successfully implement the requested behaviour with the help of Jira Workflow Toolbox.

A matching use case is documented here.

 

Just please be aware of a known bug JSDSERVER-5781: you can only attach your custom error message to the end of the generic one and therefore have to select the Summary field at Field to show the message in the post function configuration.

Best regards,
Thorsten

Not trying to revive a dead topic here. I'm still struggling to find the answer. I've tried numerous plugins.. and doing this 3 different ways. A custom script, Universal Boolean Validation, and through JQL all of which fail.

I'm starting to think that an attachment is attached differently through the portal then when to an issue seeing as though a JQL validation isn't even working from the portal. All these methods work on all other places on the workflow except on create.

Does anyone have any suggestions on how to do this? (I am after the same exact thing I believe - Conditionally validating an attachment through the portal based on a CF single select field selection)

Hi @Steven Mustari,

having tested the use case documented here just now, I'd recommend having a look at Jira Workflow Toolbox, since it should solve your problem.

If you run into problems, feel free to ask.

Cheers,
Thorsten

Hi Thorsten,

are you sure this really works with JIRA Service Desk Portal as well???

If so, please convert your reply to an answer so I can mark it as solution to this question.

Thank you & Best Regards,

Christian

Added my reply as a seperate answer.

Cheers.

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.

Hey do we have some way to check and scan the attachments in confluence, before they are uploaded and stop them with a message if it has sensitive data through script runner?

Hi Prudhvi,

your reply to my question sounds like a whole new question and is moreover Confluence related while this thread is Service Desk related. Re-using existing questions for new topics is never a good idea.

I would recommend opening a brand new question instead  - it´s dead-simple, believe me ;-)

Best Regards,

Christian

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

442 views 8 26
Read article

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