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

Mahesh Kallepalli January 14, 2020

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. 

 

 

 

3 answers

1 accepted

1 vote
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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

Mahesh Kallepalli January 16, 2020

@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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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
Jurica Petricevic
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.
October 21, 2021

can i get some more info here? Its not working for me.

0 votes
Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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.

Mahesh Kallepalli January 14, 2020

@Jack Brickey 

 

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

Like Lenin Raj likes this
Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2020

I assume Leo’s answer works for you?

Suggest an answer

Log in or Sign up to answer