How can I search for issues where a label was added within a date range?

Esther Strom
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 12, 2019

We're looking for a way to find issues that have had a specific label added before a specific date.

I've used JQL to find changes in fields before, using queries like

 

status WAS "Resolved" BY jsmith BEFORE "2019/02/02"

But when I try to use any of the "history" functions (including WAS), I get an error saying that "History searches do not support the 'labels' field."

 

How can we do a search that will give us what we need? We do have ScriptRunner, which includes the Enhanced Search. We are on Cloud. 

3 answers

2 votes
GP November 13, 2019

Hi Esther,

The labels field does not currently hold an updated date or time in a manner that is accesible with JQL as history searches do not support the 'labels' field.

Please check the description of this ticket. Atlassian rejected this due to the limited demand

https://jira.atlassian.com/browse/JRASERVER-36694

Meanwhile, you can try, if this solves your problem up to a certain extent.

Sample JQL

project = "Project Name"AND labels in ("Label Name") AND updated > -1d

 

Thanks,

Gaurav

Esther Strom
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 13, 2019

Thank you, but I know that query will not get us what we need, because updated will get you any ticket where any of many fields were updated. We need to be able to specify specifically when the labels field was updated.

Like GP likes this
GP November 13, 2019

Yes totally agree with you! but history searches do not support the 'labels' field & Atlassian is not going to work on this in near future.

https://jira.atlassian.com/browse/JRASERVER-36694

 

Thanks,

Gaurav Pratap [GP]

1 vote
Mark Kern [SaaSJet] December 27, 2019

Hi @Esther Strom 

As an alternative solution, you can try Issue History.
With this app, you could select issues by Label and monitor the history of all changes that were made in issues by dates you need.

Hope it helps

0 votes
Kyle Smith November 8, 2022

This is an old thread, but I have solved this problem with a script using the Jira API, filtering through the ticket changelog. 

def jiraDateToDaysDelta(date: str) -> int:
'''Return the delta in days between now and the date provided'''
date = date.rsplit('-', 1)[0] # Remove timezone
return (datetime.now() - datetime.fromisoformat(date)).days

def ticketHasLabelInTimeframe(ticket: JiraTicket, label: str, LOOKBACK_TIME: int) -> bool:
'''Determine if a label was added to a ticket within the lookback time'''
for update in ticket.changelog.histories:
for field in update.items:
if field.field != 'labels':
continue
if label not in field.toString.split() or label in field.fromString.split():
continue # Skip if label is not present in "TO" or present in "FROM"
if jiraDateToDaysDelta(update.created) <= LOOKBACK_TIME:
return True
else:
# If the ticket is new, or the label was added at ticket creation, this clause is hit
if label in ticket.fields.labels and jiraDateToDaysDelta(ticket.fields.created) <= LOOKBACK_TIME:
return True
return False

Suggest an answer

Log in or Sign up to answer