Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Validating Against Pick Date Field

Justin Whitaker March 18, 2019

Hi Community,

 

I am trying to validate against the pick date field before allowing an issue to be created. Basically it would look like this:

If "A" and not "B" check if date selected is 48 hours from today's date. If YES validate, if NO display warning and do not validate.

If not "A" and "B" check if date selected is 48 hours from today's date. If YES validate, if NO display warning and do not validate.

If "A" && "B" check if date selected is 96 hours from today's date. If YES validate, if NO display warning and do not validate.

 

I am relatively new to Jira and picking it up rather quickly, but have limited experience with Groovy and how it works. I do have script runner and have gotten some easier validation to work, but this one is beyond me at the moment. Here is what I have so far. Note that the numeric values that I have in here were pulled from querying MySQL to get the field value. I basically have it structured to read as IF NOT "the value for none" AND "the value none" (this would be my first example from above).

 

// required imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*

// get pointers to the required date field and store its vaule as a date
// cf is for custome field
def cf = getFieldByName("Date Required")
def cfval = cf.getVaule() as Date

// get todays date
def today = new Date()

// get date of +48
def twodays = today.plus(2)

// get date of +96
def fourdays = today.plus(4)

// get custom fields vaule
def cutTypeValue = getCustomFieldValue("10609")
def stainedValue = getCustomFieldValue("10615")

// logic check to see if the required date meets the requirments
if (cutTypeValue != ("10514") && stainedValue = ("10518")) {
if (cfval.before(fourdays)) {
cf.setError("You must select a date that is at least 96 hours from the requested date.")
}
else if (cutTypeValue != ("10514") && stainedValue = ("10517")) {
if (cfval.before(twodays)) {
cf.setError("You must select a date that is at least 48 hours from the requested date.")
}
}
else if (cutTypeValue == ("10514") && stainedValue = ("10518")) {
(cfval.before(twodays)) {
cf.setError("You must select a date that is at least 48 hours from the requested date.")
}
}
else {
cf.clearError
}
}

 

Thanks for any feed back in advance and if there is a different  way to go about this, feel free to suggest.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events