This worked well as a Simple Scripted Validator, there I didn't have to include the "import". Now I'm trying to run this elsewhere and I'm getting the error message:
What else should I include regarding dates or comparisions?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
def startTime = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("Start Date");
def currentDate = new Date()
if (currentDate.getHours()>=12){
currentDate.plus(2).clearTime().compareTo(startTime) <= 0
}
else {
currentDate.plus(1).clearTime().compareTo(startTime) <= 0
}
Hi there
The main problem is that your startTime is a field and not a field value.
You will need to get the field value from an issue. Depending on where you run the code you might already have access to the issue or not.
Assuming you are running the code where you have access to an issue, try this:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def startDateField = customFieldManager.getCustomFieldObjectsByName("Start Date")[0]
def startTime = issue.getCustomFieldValue(startDateField) as Date
def currentDate = new Date()
if (currentDate.getHours()>=12){
currentDate.plus(2).clearTime().compareTo(startTime) <= 0
}
else {
currentDate.plus(1).clearTime().compareTo(startTime) <= 0
}
For this to work, it depends where you run it.
Thanks! I'm not getting any errors now but the script doesn't validate the date anymore, it lets me enter a date which originally I shouldn't. I'm running it form Automation for Jira, after a condition (if a certain customer request type is selected) this script is executed.
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.