JQL search for items in custom timerange

Paddy Byrne May 20, 2016

Hi - I need to search for issues created in the last month for a report dashboard, however the business rules of the company for reporting purposes is that their month ends on the last Friday of every normal calender month. I had been using

createdDate > startOfMonth(-1) and createdDate < endOfMonth(-1)

but it is naturally starting on the 1st and ending on either the 30th or 31st, as you would expect, so this is close, but not actually doing exactly what i need.

To give a specific example of what I need, in April of 2016, I want to filter for anything in the previous month. So based on the business rule that Friday is the last day,  I want the filtered range to end Friday 25th March, but the tricky part is the start of the range is actually 27 Feb.

I need the filter to be reusable, so obviously cant hard code and dates etc. Any ideas as to how I could search for my custom period? 

1 answer

3 votes
JamieA
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.
May 22, 2016

I don't think you can do this without a custom JQL function. Normally I would be suggesting writing your own with ScriptRunner, but there is a small bug that prevents using relational operators with custom functions. I've fixed it, but won't be released for a couple of weeks. 

If you want to write your own see https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/jql-function-plugin-module, the important stuff for getting the last Friday of every month is in the getValues method. Code is at https://gist.github.com/jechlin/25557469af8b8013f62c6e4d3852be27.

So to get stuff resolved in the previous month you would use:

resolutiondate > endOfBusinessMonth(-2) and resolutionDate <= endOfBusinessMonth(-1)

 

 

Paddy Byrne May 23, 2016

Thanks very much Jamie, I'll save this in my script root and will wait for the SR update you mentioned to trial it...

Like Josh Simnitt likes this

Suggest an answer

Log in or Sign up to answer