The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Due date field control

Marat
January 25, 2019

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
YARON LEVY
Contributor
December 15, 2019

getFieldById("duedate").value

0 votes
Tarun Sapra
Community Champion
January 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 Champion
January 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.

Marat
January 25, 2019

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

Tarun Sapra
Contributor
January 25, 2019

See the behaviour API, they are fix of groovy and JS

https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html

Marat
January 25, 2019

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 Champion
January 25, 2019

Hello @Marat

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

Marat
January 25, 2019

Yes I did

Tarun Sapra
Community Champion
January 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.

Marat
January 25, 2019

contro due.PNG

Tarun Sapra
Community Champion
January 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 Champion
January 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

TAGS
AUG Leaders

Atlassian Community Events