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

0 votes
YARON LEVY December 15, 2019

getFieldById("duedate").value

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 January 25, 2019

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

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

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 25, 2019
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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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

Suggest an answer

Log in or Sign up to answer