Need help finding past due issue in Listener

I am having trouble with finding past due issues in my Listener. I know that the JQL is duedate < now(). I have translated this to the following in my Listener:

Date dNow = new Date();
def jqlQueryParser = cm.getComponentInstanceOfType(JqlQueryParser.class) as JqlQueryParser
JqlQueryBuilder builder = JqlQueryBuilder.newBuilder()
builder.where().due().lt(dNow)

The query doesn't find any issues ( I know there are 3). I think I am having trouble with the dNow Date format but can't figure it out. What am I doing wrong?

George

2 answers

1 accepted

I figured it out:

builder.where().due().lt("0d")

Since I want to find due date before today, I can search for due < 0d.

George

Awesome. Seems it is expecting worklog format and not actual date. I was going to suggest parsing JQL String. That can be another option for more complex queries like finding issues due before startOfDay.

0 vote

Try

builder.where().dueAfter(dNow)

Nope - still see no issues.

TST-1 was due on 2013-03-05 00:00:00.0 <- issue.getDueDate().toString()

dNow.toString is Tue Mar 26 15:14:09 CDT 2013

It should have caught TST-1

Logically I'm not sure that made sense. Find issues that are due after now?

Anyways, I also setup a date of 1970 and tried to use .dueBetween(d1970, dNow) and still get no results. If I change my query to .project("TST") it finds results, so it's not anything else in my code.

I am sorry, I meant dueBefore, which dioesn't exist. I would have asked you to try dueBetween as you tried but seems it is not working either!

Quick question, are you able to find it from UI? Is it not working only via code?

Correct - from the GUI I can do a duedate < now() and see the issues that should show. From the code, nothing shows.

print/log the where clause or query, and let us know what it says.

Here is what the code is at:

Date oldDate = new Date();
            oldDate.setTime((long) 1);
            Date dNow = new Date();
            
            def jqlQueryParser = cm.getComponentInstanceOfType(JqlQueryParser.class) as JqlQueryParser
            JqlQueryBuilder builder = JqlQueryBuilder.newBuilder()
            builder.where().dueBetween(oldDate,dNow)

            Query query = builder.buildQuery()
            SearchService searchService = cm.getInstance().getSearchService();
            def qry_results = searchService.search(jadmin_user, query, PagerFilter.getUnlimitedFilter())
            
            def whereClause = query.getWhereClause()
            log.debug "where clause: " + whereClause.toString()

The debug statement prints:

where clause: {due >= "1969-12-31 18:00"} AND {due <= "2013-03-26 20:44"}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

76 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you