I have created two custom date picker fields, START DATE and END DATE. These two fields are used on Create Issue Screen.
I am using script runner addon to I validate END DATE against START DATE.
User should not be allowed to choose an End Date that is much before the Start Date.
As an end result, user should be not allowed to create ticket if END DATE chosen is prior to the START DATE
Request help from the Community !!!
Following is the code that I have added in Script Console:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.web.action.util.CalendarResourceIncluder
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def startDateField = customFieldManager.getCustomFieldObjectByName('Start Date')
def startDateValue = issue.getCustomFieldValue(startDateField)
def endDateField = customFieldManager.getCustomFieldObjectByName('End Date')
def endDateValue = issue.getCustomFieldValue(endDateField)
Calendar calendar = Calendar.getInstance(TimeZone.getDefault())
calendar.setTime(startDateValue)
calendar.setTime(endDateValue)
// validation end date
if (endDateValue != null){
if(startDateValue > endDateValue){
invalidInputException = new InvalidInputException("End Date must be greater than Start Date")
}
// validation start date
if (startDateValue != null){
if(startDateValue > endDateValue){
invalidInputException = new InvalidInputException("End Date must be greater than Start Date")
}
}
// This block validates end date against start date
if (issue.endDateValue) {
if (issue.endDateValue?.before(Calendar.getInstance().getTime()))
{
invalidInputException = new InvalidInputException("End date must be in the future")
}
}
When I run the above code, I get following error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script177.groovy: 22: expecting ')', found ';' @ line 22, column 23. if(startDateValue > endDateValue){ ^ 1 error
You have copied and pasted this script from somewhere without reading it properly. It's html encoded and you need to convert it back into the original plain-text
Thanks, Nic
I have converted the code using html to text converter, still no success
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please, do not assume that a converter has done it correctly.
If you're getting the same error, then your converter does not understood that the content is code and not converted it correctly. Please write the code properly.
If there is a different type of error, one that is not an encoding error, then we'll need to see what it is, and what the error is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.