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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published yesterday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

407 views 5 5
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