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.
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
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) .
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can i get some more info here? Its not working for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your response at this moment we are using scriptrunner is it possible to achieve.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I assume Leo’s answer works for you?
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.