It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cannot find matching method: compare dates

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

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.

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