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

Christian Schlaefcke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 18, 2017

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

1 vote
Answer accepted
Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 9, 2018

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

1 vote
Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2018

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)

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 9, 2018

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

Christian Schlaefcke December 9, 2018

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

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 10, 2018

Added my reply as a seperate answer.

Cheers.

0 votes
prudhvi godithi November 28, 2018

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?

Christian Schlaefcke November 28, 2018

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

0 votes
Athena Petridou [Nimaworks] August 22, 2017

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

Christian Schlaefcke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 22, 2017

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

Athena Petridou [Nimaworks] August 23, 2017

Hey again,

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

Christian Schlaefcke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 23, 2017

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.

Koen Gillard December 15, 2017

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
TAGS
AUG Leaders

Atlassian Community Events