Make Attachment mandatory on create screen "..../secure/CreateIssue.jspa"

kanishka December 9, 2020

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

 

 

attachement1.PNGattachement2.PNG

1 answer

0 votes
mogavenasan
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.
January 10, 2021

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

kbharadwaj_ctepl_com January 10, 2021

Hi

kanishka January 10, 2021

Hi @mogavenasan , I did raise this concern to scriptrunner support.

Now its an open issue from their side.

https://productsupport.adaptavist.com/browse/SRJIRA-4919

mogavenasan
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.
January 10, 2021

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.

kanishka January 11, 2021

Yes Attachment is require.
(*) is not coming because attachment are not always mandatory. When Checkbox is checked then only it will be required.

mogavenasan
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.
January 11, 2021

Hi @kanishka

I tested Modify field descriptions on my local machine and it works on the URL; <base URL>/secure/CreateIssue.jspa.

image.png

That being said, the testing confirmed that Behaviour works on pop up screens and <base URL>/secure/CreateIssue.jspa URL.

Thanks,
Moga

Suggest an answer

Log in or Sign up to answer