Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I validate a custom date time is set to at least 3 days ahead of the current time? Edited

Hi,

I have a Date-Time custom field.  I want to enforce that users set it to at least 3 days ahead of the present time.  For example, if today is January 1st, this field should be set to January 4th or later.

I tried the following Scriptrunner behavior below.  Added it is a server-side script to my custom field:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.customfields.impl.DateTimeCFType
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours


def futuredate = new Date().plus(3)

def dateFld = getFieldById(fieldChanged)
def dateValue = dateFld.value as Date
dateFld.clearError()

if (dateValue < futuredate){
dateFld.setError("Requested Date cannot be before (${futuredate})")
}

It does not have a compile error, but does not enforce the behavior I want.  Seems like nothing happens.   Any ideas how to fix my script?

1 answer

1 accepted

2 votes
Answer accepted

I tested the script that you provided as a server-side script Behavior for a Date/Time picker custom field, but it worked fine for me. Do give this one a try and let me know how it goes :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def date2 = new Date().plus(3)

def dateField = getFieldById(fieldChanged)
def dateValue = dateField.value as Date

if (dateValue < date2){
dateField.setError("Date cannot be earlier than (${date2})") 
}

It should fulfill the same requirement but is a more simplified version.

@Tye Joe Wai .  Thanks.

So when I tried this script, it correctly throws the error message when I pick an invalid date.   However, when I fix the date, it still shows the error message and won't let me proceed.

I tried it with both Date and Date-Time fields with the same results.  Any idea how to clear the error when the date is fixed?

Fixed it by adding this after the def statements.

dateField.clearError()
Like Vikrant Yadav likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

196 views 6 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you