Is it possible to restrict the Due Date field entry to only take today's and future dates.

Musku Nagaraju May 6, 2019

I need to setup the Due Date field to accept only Today's and future dates, but not past dates. Can this be done with using behavior?

I have used "Date Expression Compare" in create transition it is working in create issue screen, but our Estimated Completion Date field is editable on the view and people sometimes pick a date in the past. A validator won't help since there is no transition

Thanks

Nagaraju

 

3 answers

1 accepted

0 votes
Answer accepted
Musku Nagaraju May 9, 2019

I tried with different code, it is working for me

// required import statements
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*

// Get pointers to my date field and get its value as a date

def cf = getFieldByName("Promo End date")
def cfval = cf.getValue() as Date

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

// if the date entered is before todays throw an error
if(cfval.before(yesterday)) {
cf.setError("You must not enter a date that is before todays date")
// if the date entered is over three months throw an error
}else{
cf.clearError()
}

 

 

Thanks

Nagaraju

0 votes
Kiran Talapaneni September 21, 2021

This worked for me:

def duedatefield = getFieldById("duedate")
Date duedatevalue = (duedatefield.value as Date)

//today
def today = new Date()


if(duedatevalue.getDate() < today.getDate()){
duedatefield.setError("Please select today's date or future dates")
} else{
duedatefield.clearError()
}
Harish Tuccapuram April 9, 2023

Thanks @Kiran Talapaneni  it worked for me and i would like to have users to select the due date only 3 or more day can you suggest me.

0 votes
Andreas Lorz May 6, 2019

Hi @Musku Nagaraju ,

as you assumed, you can use Behaviours to realize that. This will check the field permanantyl if the defined condition is valid. 

I try to build it very quickly, feel free to try it. (I hope duedate is the fieldId of the field)

duedatefield = getFieldById("duedate")
Date duedatevalue = (duedatefield.value as Date)

//today
def today = new Date()


if(duedatevalue.getTime() < today.getTime()){
duedatefield.setError("your error message")
} else{
duedatefield.clearError()
}

 best regards.

Musku Nagaraju May 7, 2019

@Andreas Lorz ,  Thanks for you inputs but this is not working for me. 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

import com.atlassian.jira.component.ComponentAccessor

def duedatefield = getFieldById("10701")
Date duedatevalue = (duedatefield.value as Date)

//today
def today = new Date()

if(duedatevalue.getTime() < today.getTime()){
duedatefield.setError("Due date always feature date`")
} else{
duedatefield.clearError()
}

 

Can we help me out to set the Promo end date always feature date of Promo start date 

e.g If I select promo start date  10-May-2019, then Promo end date should be allow post 10 th may only..

Suggest an answer

Log in or Sign up to answer