Behaviour script to validate the given data/time field which should accept value after one hour from current time

Behaviour script to validate the given data/time field which should accept value after one hour from current time.

Its custom field name - Planned Implementation Data/Time.

2 answers

Hi Vignesh,

I have attached a sample Behaviours script that I have created on my local JIRA 7.1 instance which takes the value from a custom date picker picker field called DemoTimeField and checks if the value entered is less than 1 hour from the current date and time and if it is presents the user with an error and forces them to enter in a  value greater than 1 hour from the current date and time.

I have attached the code, config and a screenshot of the output below.

Code

//Required Imports
import groovy.time.TimeCategory
import java.util.Date

// Get a pointer to my Date Custom field
def DateField = getFieldByName("DemoTimeField")
Date DateVal = (Date) DateField.getValue()

// Get todays date
def timeIn1Hour = new Date()

// Add 1 hour to todays date
use( TimeCategory ) {
    after60Mins = timeIn1Hour + 60.minutes
}

// Check if the Start Date is before todays date plus 1 hour and if so present the user with an error and clear the value to the field to force the user to enter in a correct value.
if(DateVal.before(after60Mins)){
    DateField.setError("You are only allowed to select a Date and time that is greater than 1 hour from now" + "<br/>" + "Your selected date and time has been cleared to prompt you to select a valid value")
    // Clear the weekday value to make the user re select a new value as well
    DateField.setFormValue(null)
}else{
    // If a valid value is entered clear any errors and accept the value
    DateField.clearError()
}

Config

Screen Shot 2016-08-26 at 15.56.33.png

Output

Screen Shot 2016-08-26 at 15.48.52.png

I hope this helps.

Thanks

Kristian

Planned Implementation Data/Time  value should not be less than one hour from current time.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 4 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

16 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you