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?
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fixed it by adding this after the def statements.
dateField.clearError()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a date time field that during creation, if it is after 830am CST we will not allow that date to be set the same day . Any thoughts on how to validate that in a workflow create step?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.