Cannot find matching method: compare dates

Zita Bagi
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.
December 20, 2019

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:

Untitled.png

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
}

 

1 answer

0 votes
Leonard Chew
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.
December 20, 2019

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.

Zita Bagi
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.
December 20, 2019

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.

Suggest an answer

Log in or Sign up to answer