I have two code sets of code for the date picker custom field named - Issue close date
one is for future date not allowed and the other one is the that the close date should not be before the issue start date.
" The future date not allowed" feature was working earlier. But when I added one more behavior to show the message "close date should not be before the issue start date" the future date not allowed message is not coming. It is now allowing future dates. Could you look into the issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*
def startDateField = getFieldByName("issue Detected Date")
def startDateValue = startDateField.getValue() as Date
def dueDateField = getFieldByName("issue Closed Date")
def dueDateValue = dueDateField.getValue() as Date
def strErrorText = "Closed Date must be greater than Detected Date"
if(startDateValue > dueDateValue){
dueDateField.setError(strErrorText)
}else{
dueDateField.clearError()
}
import com.atlassian.jira.component.ComponentAccessor
import java.util.Date.*
//get the Date Field here
def cfDate = getFieldByName(" issue Closed Date")
def date= cfDate.getValue() as Date
//get today's date
def today = new Date()
// In case today+1 date needs to be checked
//def tomorrow = today.plus(1)
//Check the condition for date less than are equal to today
if(date.after(today)) {
cfDate.setError("Future date not allowed")
}else{
cfDate.clearError()
You can not have 2 different behaviours run on the same field.
The last one to be evaluated (and you can't control the order) will win.
If you have to combine your 2 scripts into 1 that will account for both possibilities.
I combined the code . But it s not working
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*
def startDateField = getFieldByName("Defect Detected Date")
def startDateValue = startDateField.getValue() as Date
def dueDateField = getFieldByName("Defect Closed Date")
def dueDateValue = dueDateField.getValue() as Date
def strErrorText = "Closed Date must be greater than Detected Date"
//get the Date Field here
def cfDate = getFieldByName("Defect Detected Date")
def date= cfDate.getValue() as Date
//get today's date
def today = new Date()
if(startDateValue > dueDateValue){
if(date.after(today)) {
cfDate.setError("Future date not allowed")
dueDateField.setError(strErrorText)
}else{
dueDateField.clearError()
}
// In case today+1 date needs to be checked
//def tomorrow = today.plus(1)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try it like this:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*
def startDateField = getFieldByName("Defect Detected Date")
def startDateValue = startDateField.getValue() as Date
def dueDateField = getFieldByName("Defect Closed Date")
def dueDateValue = dueDateField.getValue() as Date
startDateField.clearError()
dueDateField.clearError()
def strErrorText = "Closed Date must be greater than Detected Date"
//get today's date
def today = new Date()
if(startDateValue > dueDateValue) {
dueDateField.setError(strErrorText)
}
if(startDateValue.after(today)) {
startDateField.setError("Future date not allowed")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The same script has to be placed in both the Defect Detected Date and Defect Closed Date server-side script.
Beyond that, I'll need to see more concrete examples with screenshots etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This looks good. What's the problem?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want Closed Date must be greater than detected date and Futured date not allowed for Defect close date field. I am not getting both the messages .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah... all your code example about Future date appeared to be on the Detected Date.
Try this way:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*
def startDateField = getFieldByName("Defect Detected Date")
def startDateValue = startDateField.getValue() as Date
def dueDateField = getFieldByName("Defect Closed Date")
def dueDateValue = dueDateField.getValue() as Date
startDateField.clearError()
dueDateField.clearError()
def strErrorText = "Closed Date must be greater than Detected Date"
//get today's date
def today = new Date()
if(startDateValue.after(today)) {
startDateField.setError("Future date not allowed")
}
if(dueDateValue.after(today)) {
dueDateField.setError("Future date not allowed")
}
if(startDateValue > dueDateValue) {
dueDateField.setError(strErrorText)
}
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.