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

Behaviour message not getting displayed

Garden16_ February 3, 2022

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()

 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Peter-Dave Sheehan
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.
February 3, 2022

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.

Garden16_ February 9, 2022

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)

}

Garden16_ February 9, 2022

let me know if mixing of the code is correct or not

Peter-Dave Sheehan
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.
February 9, 2022

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")
}
Garden16_ February 9, 2022

only the first msg is getting displayed unfortunately .

Peter-Dave Sheehan
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.
February 9, 2022

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.

Garden16_ February 9, 2022

defect detected date  field on new defect screen 

 Create new defect  screen - defect detetected date.PNG

Garden16_ February 9, 2022

close defect screen - closed defect.PNG

Peter-Dave Sheehan
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.
February 9, 2022

This looks good. What's the problem?

Garden16_ February 9, 2022

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 .

Peter-Dave Sheehan
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.
February 9, 2022

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)
}

Garden16_ February 10, 2022

Thank you  so much ! it worked !

TAGS
AUG Leaders

Atlassian Community Events