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
Hi @kanishka,
Looking at both of the screenshots, it looks like the Attachment field is not mandatory. Please clarify this.
Have you also checked the browser Console log to see if there is any Scriptrunner is logging?
Thanks,
Moga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @mogavenasan , I did raise this concern to scriptrunner support.
Now its an open issue from their side.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @kanishka,
What I meant was; you mentioned this:
Script is working fine on create screen pop up window
However, from the screenshots, we are seeing the Attachment field is not required. The required field will have (*) sign at the end of the field name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes Attachment is require.
(*) is not coming because attachment are not always mandatory. When Checkbox is checked then only it will be required.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @kanishka,
I tested Modify field descriptions on my local machine and it works on the URL; <base URL>/secure/CreateIssue.jspa.
That being said, the testing confirmed that Behaviour works on pop up screens and <base URL>/secure/CreateIssue.jspa URL.
Thanks,
Moga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.