Looking for script or SQL to retrieve unuse custom fields Edited

JIRA 6.2.2

HI,

I have 600 custom fields and would like to do clean up.

Is there a script (script runner)/SQL that returns custom fields have not been used for the pass 6 months?

I am aware I can do filter like:
"My custom field" is not EMPTY and createdDate < endOfMonth(-6)

but I don't want to do that 600 times.

Also aware there is/are plug-ins but looking for script (script runner)/SQL.

 

Thanks.

1 answer

1 accepted

Answered my own question.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()def
customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)

List<CustomField> cfObjects = customFieldManager.getCustomFieldObjects()


for (cf in cfObjects) {
        def query = jqlQueryParser.parseQuery(cf.getClauseNames().getPrimaryName() + " is not EMPTY and created > -180d")
        def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

       if (results.total == 0) {
            //these are the unused fields
            log.debug(cf.getName() + "," + cf.getClauseNames().getPrimaryName() + "," + cf.getCustomFieldType().name)
        }
}

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,146 views 13 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot