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

Date Custom Field has to be show upcoming days not previous dates based on selection of before date

Hello ,

 

Our requirement is we have multiple different date fields on different transitions suppose in open they have entered current date in next transition the other date field doesn't not want to show old dates to enter it has to show only future date to enter . Is there any way to restrict like these.

 

Going linear on transitions we have lots of date fields has to enter and track days and time on each step so can we restrict the user not to enter old days.

 

Thanks & Regards,

Mahesh. 

 

 

 

2 answers

1 accepted

1 vote
Answer accepted
Leo Community Leader Jan 14, 2020

Hi @Mahesh Kallepalli,

Scriptrunner's Behaviour does allow you to validate and set Error on the field while you are on the create/edit screen itself

Below script may give you some idea

NOTE: this script is for behaviour to validate while on the screen. if you want to validate same in validator then script needs some changes

 

import java.util.Date.*

def cfDate = getFieldByName("Batch Start")
def date= cf.getValue() as Date

// get todays date
def today = new Date()
// get yesterdays date
def yesterday = today.minus(1)

// if the date entered is before today's throw an error, if you use today instead of yesterday in IF, it'll throw error for today's date as well

if(date.before(yesterday)) {
cfDate.setError("You must not enter a date that is before todays date")
}else{
cfDate.clearError()
}

 BR,

Leo

@Leo 

It works fine is there any option to get dynamically as we are having multiple status on every transitions there are they will enter start date and End date. Please find below screen shot for your reference instead of writing multiple Behaviour's

For sample I have written two behaviour but I can't get value from Data collection end date(one behaviour) to RFP Prep start Date(Another behaviour) .

Dates SYS.JPG

Leo Community Leader Jan 16, 2020

Hi @Mahesh Kallepalli,

I don't think there is a way to fetch fields dynamically

You can add/include fields(which are available in the same screen/transition) but it does have a drawback

import java.util.Date.*

def cfStart = getFieldByName("Start Date")
def dateStart= cfStart.getValue() as Date

def cfEnd = getFieldByName("End Date")
def dateEnd= cfEnd.getValue() as Date

// get todays date
def today = new Date()
// get yesterdays date
def yesterday = today.minus(1)

// if the date entered is before today's throw an error, if you use today instead of yesterday in IF, it'll throw error for today's date as well

if(dateStart.before(yesterday)) {
cfStart.setError("You must not enter a date that is before todays date")
}else{
cfStart.clearError()
}
if(dateEnd.before(yesterday)) {
cfEnd.setError("You must not enter a date that is before todays date")
}else{
cfEnd.clearError()
}

 

The drawback is the script will be invoked/run only when the mapped field is getting updated/changed in the screen

e.g. I mapped Start Date to behaviour script, 

I selected past date in End Date field first(Script won't be invoked here and won't set error). then I selected/edited Start Date. now the script will be invoked and set error for End Date field as well

But I won't suggest this though as it won't work as expected if engineers missed to edit in a order

 

BR,

Leo

0 votes
Jack Community Leader Jan 14, 2020

there are some limitations on what you can do here OOTB. You can use validators during transition to prevent transitions if a date is in the past. But you cannot prevent setting a date in the past on the Edit screen. So you could either remove the date field from the Edit screen and set them up on transition screens where you can validate w/ an error message if in the past. You can consider an addon for this that could restrict the field, e.g. scriptrunner or others.

@Jack 

 

Thanks for your response at this moment we are using scriptrunner is it possible to achieve.

Like Lenin Raj Rajasekaran likes this
Jack Community Leader Jan 14, 2020

I assume Leo’s answer works for you?

Suggest an answer

Log in or Sign up to answer
TAGS

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