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

Due date field control Edited

Hello 
Tell me how to set due date field to exclude the possibility of choosing the past date. Maybe you will advise plugins.

2 answers

0 votes
Tarun Sapra Community Leader Jan 25, 2019

Hello @Marat

It's possible but with plugins.

You can do it using Behaviour module of the Script runner plugin.

Tarun Sapra Community Leader Jan 25, 2019

You can add field mapping for the due date field in the behaviour section and check everytime the user enters the value if the value of the date is "last date" or not. And if it's the last date then you can show the error message.

Need to use a Groovy script? Or can this be done through a gui? 

I found the script, but it does not work. can you help ?

import groovy.time.TimeCategory
import java.util.Date

def DateField = getFieldByName("due date")
Date DateVal = (Date) DateField.getValue()

Date now = new Date()

if(underlyingIssue.getDueDate().before(now)){

DateField.setError("Error")

DateField.setFormValue(null)
}else{
DateField.clearError()
}
Tarun Sapra Community Leader Jan 25, 2019

Hello @Marat

Have you done the field mapping in the behaviour module for the due date field.

Yes I did

Tarun Sapra Community Leader Jan 25, 2019

Can you share the screenshot of the configuration, also can you add some logging to your code 

log.info " .....text here ..."

So that we know for sure that the code is being executed.

Tarun Sapra Community Leader Jan 25, 2019

For getting the due date object you can use the code

def dateField = getFieldById(getFieldChanged())

Also issue.getDueDate() return the object "class java.sql.Timestamp" and not "Date" as your code has date comparison, thus I would suggest you to add right type casting and may be in logs just print the value of the "due date" field before comparison and make sure both objects are of same type.

Tarun Sapra Community Leader Jan 25, 2019

Since Timestamp is a sub-class of Date thus you can assign the value to Date object.

https://docs.oracle.com/javase/8/docs/api/java/util/Date.html

getFieldById("duedate").value

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