Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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

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.

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

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
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,193 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you