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

Validating Against Pick Date Field Edited

Justin Whitaker Mar 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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira Service Desk

4 changes to queues and issues you don’t want to miss

Hello Atlassian Community! I'm Tania, a Senior Product Marketing Manager for Jira Service Desk Cloud! I'm excited to announce some exciting improvements coming up for those who work with queues and...

662 views 9 13
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