Hi
I am using simple scriptrunner validator to make attachment mandatory on create screen on basis of value of check box. Script is working fine on create screen pop up window but when we use new tab to create issue ex "abc/secure/CreateIssue!default.jspa" , script is not checking attachment while creation.
Here is my script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import org.apache.log4j.Level
import org.apache.log4j.Logger
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
// Set log level
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)
final fieldName = 'Attachments'
final wantedOptions = ['Motor Position Calibration Test Report', 'Motor Position Calibration (.xml)','Final Function Dyno Report','Final Function Dyno (.xml)']
def customFieldManager = ComponentAccessor.customFieldManager
def checkBoxFieldA = customFieldManager.customFieldObjects.find { it.name == fieldName }
def checkBoxFieldAValue = issue.getCustomFieldValue(checkBoxFieldA)
// If checkbox does not contain values, it is not needed to continue
if (!(checkBoxFieldAValue in List)) {
return true
}
def selectedOptions = checkBoxFieldAValue?.collect { (it as LazyLoadedOption).value }
//def containsAllWanted = selectedOptions.contains(wantedOptions)
log.debug("""
selected Options string list = $selectedOptions
""")
if (selectedOptions) {
// if(ComponentAccessor.attachmentManager.getAttachments(issue).size() >= 1)
// return true
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.error("Uploaded attachment name: ${it.filename}")
}
if(!tempWebAttachments){
throw new InvalidInputException(IssueFieldConstants.ATTACHMENT,
"You must upload attachment")
return false
}
else
return true
}
}
else
return false

