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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,709
Community Members
 
Community Events
176
Community Groups

Behaviour message not getting displayed

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

1 vote
Answer accepted

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)

}

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

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

only the first msg is getting displayed unfortunately .

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.

defect detected date  field on new defect screen 

 Create new defect  screen - defect detetected date.PNG

This looks good. What's the problem?

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 .

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

Thank you  so much ! it worked !

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events