Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,026
Community Members
 
Community Events
165
Community Groups

Compare two date fields and validate transition

I have two custom date fields: Start Date and End Date.

I want to check if End Date is set before Start Date in which case I want to stop ticket creation and let the users know that End Date cannot be set before Start Date.

I do have scriptrunner, but I didn't find a straightforward solution.

Thank you!

1 answer

Hi @Bojan Virag

you could use a custom script condition with the following code:

import com.atlassian.jira.component.ComponentAccessor

def cfStartDate = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Start Date").first()
def cfEndDate = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("End Date").first()
def startDate = issue.getCustomFieldValue(cfStartDate) as Date
def endDate = issue.getCustomFieldValue(cfEndDate) as Date

passesCondition = (startDate != null && endDate!= null && startDate <= endDate)

Thank you for the complete solution @Andrea Pannitti ! I will give it a try later today and post the result.

Hi @Bojan Virag

if my solution is fine for you, please, could you accept it?

 

Thank you

Suggest an answer

Log in or Sign up to answer
TAGS

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