Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to validate the transition by the number of attachments on Customer Portal request?



I'm trying to validate the number of attachments in a transition. You can get temporary attachments through form token or id temporary attachment. I am trying to access temporary attachments via form token, because I haven't found a way to get ids temporary attachments. As a result, validation only works for Jira. If you make the transition through plugin Actions for JIRA Service Desk from Customer Portal - validation fails, because form token is null and I can't get access to temporary attachments. 

How do I solve the attachment validation problem by number on Customer Poral page? How can I get form token?

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
import com.opensymphony.workflow.InvalidInputException
import org.slf4j.LoggerFactory
import org.slf4j.Logger

Logger log = LoggerFactory.getLogger(this.getClass())

def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)

def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)

if (formToken) {

    def tempWebAttachments = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)

    int attachmentsSize = tempWebAttachments.size()

    log.warn('size {}', attachmentsSize)

    if (attachmentsSize > 1) {
        throw new InvalidInputException(IssueFieldConstants.ATTACHMENT, "You can't attach more than 1 document")

    return true
} else {
  log.warn('form token is null')



Cheers, Bogdan

1 answer

Hi @Toolstrek_ LLC

A similar answer is available in this Adaptavist Library link.

The sample code provided uses the validator to restrict the number of attachments that can be added. If it exceeds the limit, the validator will return an error message.

I hope this helps to answer your question. :)

Thank you and Kind regards,


Hi, @Ram Kumar Aravindakshan _Adaptavist_ 

Thanks for your answer, but it still doesn't work for Customer Portal.

Cheers, Bogdan

Hi @Toolstrek_ LLC

Could you please try to modify the code provided in the Adaptavist Library to this:-

import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.MutableIssue

def issue2 = issue as MutableIssue

def newAttachmentNames = issue2.modifiedFields.get(IssueFieldConstants.ATTACHMENT)?.newValue as List

!(newAttachmentNames.size() > 5)

Below is a screenshot of the validator configuration:-


I have added this validator to the create transition, tested it in my environment, and it works as expected.

Below are a few test screenshots:-

1) First, when I try to create a technical support ticket, I try to enter 7 attachments. The maximum number of attachments has been set to 5. As expected, when I try to create the issue, the validator returns an error message.



2) When I remove the attachments to the max limit of 5, I can now create the ticket as shown below:-image2.png

I hope this helps to answer your question. :)

Thank you and Kind regards,


Hi, @Ram Kumar Aravindakshan _Adaptavist_ 

Plugin Actions for Jira Service Desk allows you to make transitions on a customer portal.


image.pngBut but the validation of attachments on these transitions for some reason still does not work.

Cheers, Bogdan

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events