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
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

68 views 3 2
Join discussion

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