Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to restrict date field based on check box field

Musku Nagaraju
Contributor
April 8, 2019

Hi Team,

I have check box field called Instance and values are " Dev" ,"Production", "Stage" and I have Date field called "Estimated end Date"

If I select Instance = Dev, Estimated end date should allow me to select date after 5 days.

If I select Instance = Stage, Estimated end date should allow me to select date after 10 days.

If I select Instance = Production, Estimated end date should allow me to select date after 15 days.End date.PNG

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
April 8, 2019

You could try something like this:

def instanceFld = getFieldByName("Instance")
def estimatedDateFld = getFieldByName("Estimated end date")
instanceFld.clearError()
estimatedDateFld.clearError()

if(instanceFld.value instanceof ArrayList){
instanceFld.setError("Please select only one")
return
}
if(estimatedDateFld.value){
if(!instanceFld.value){
instanceFld.setError("Please select at least one instance before selecting a date")
estimatedDateFld.setFormValue(null)
return
}
def today = new Date()
def dueDateInterval = estimatedDateFld.value - today
def instanceMinDays = [Production:15, Dev:5, Stage:10]
if(dueDateInterval <= instanceMinDays["$instanceFld.value.value"]){
estimatedDateFld.setError("Estimated end date must be more than ${instanceMinDays["$instanceFld.value.value"]} days from now")
}
}

 

I would put this code in both fields so that if either is changed, both will be re-validated

Musku Nagaraju
Contributor
April 8, 2019

@PD Sheehan it work good for me, Thanks for your help

0 votes
Tarun Sapra
Community Champion
April 8, 2019

Hello @Musku Nagaraju 

I don't think you can place a check within the date popup itself, what you can do easily (using Script runner plugin Behaviour module) is when someone selects a date and that doesn't match the criteria which you listed

like- Dev, Estimated end date should allow me to select date after 5 days.

Then the user will see an error and unless he selects another date he will not be able to submit the form.

A similar query is here - https://community.atlassian.com/t5/Jira-questions/Is-it-possible-to-restrict-the-Due-Date-field-entry-to-only-take/qaq-p/259268

The suggestions were about writing a custom validator in the workflow transition which is also possible in your case but that's server side while the behaviour module which I suggest works on client side.

Musku Nagaraju
Contributor
April 8, 2019

@Tarun Sapra , I tried this but this is not working currently what I am looking. This will allow me only to select date in future and past but not based on another filed values,

I hope this will achieve with using Script runner plugin Behavior module.

Kindly help me the right code?

 

Thanks

Nagaraju

Suggest an answer

Log in or Sign up to answer