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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,557,459
Community Members
 
Community Events
184
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!

2 answers

1 accepted

1 vote
Answer accepted
Andrea Pannitti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 19, 2022

Hi @Bojan Virag,

the problem depends on the fact that you have used the script (which was for a Custom script condition) in the creation phase.
Thus, a condition cannot be used but a validator must be used. In this case, we can use a Simple scripted validator with the following code:

def startDate = cfValues['Start Date'] as Date
def endDate = cfValues['End Date'] as Date

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

Works perfectly, thank you!

I want to compare custom date field and today

 

Below script was succeeded.

-----------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*
import utils.*

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def workpercent = customFieldManager.getCustomFieldObject("customfield_13500")

CustomField finishDateField = customFieldManager.getCustomFieldObject("customfield_10230"); //finish date
long finishDate = (issue.getCustomFieldValue(finishDateField) as Date).getTime(); //finish date value

def today = (new Date() as Date).getTime() //current datetime


if(finishDate > today) {
issue.setCustomFieldValue(workpercent, 100 as double)
} else {
return true
}

------------

 

When I use grater script, it doesn't work. 

if(finishDate > today) --> if(finishDate >= today)

 

So I tested equal condition like below, but failed. 

if(finishDate.equals(today))

if(finishDate.isequal(today))

if(finishDate.compareTo(today) == 0)

 

How can I fix?

0 votes
Andrea Pannitti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 14, 2022

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.

Andrea Pannitti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 20, 2022

Hi @Bojan Virag

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

 

Thank you

Sorry for the late reply @Andrea Pannitti I only now had a chance to test. I put the script in the create transition, and while

"passesCondition": "false (java.lang.Boolean)"

ticket still gets created?

Thank you

Suggest an answer

Log in or Sign up to answer