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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

344 views 1 18
Join discussion

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