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!
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the complete solution @Andrea Pannitti ! I will give it a try later today and post the result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.