list of unused custom fields via scriptrunner

NSEU DevOps April 24, 2023

Hello,

I am running a Datacenter instance (8.20.14) and I need to perform an audit on all unused custom fields (and we have a large amount).

I have used the Jira tool "Custom Fields Optimizer" to a list of all custom fields within a project but unfortunately, this tool does not allow an export of all custom fields to a CSV file so I can manipulate it.

Is there a way via either Scriptrunner or the API I can get this list on Datacenter?

1 answer

1 accepted

1 vote
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 24, 2023

Hi @NSEU DevOps  Check this doc for managing custom fields :- https://confluence.atlassian.com/enterprise/managing-custom-fields-in-jira-effectively-945523781.html

OR you can run the following script in Script Console to get a list of empty custom fields :- 

 

import com.atlassian.jira.component.ComponentAccessor

import groovy.sql.Sql

import org.ofbiz.core.entity.ConnectionFactory

import org.ofbiz.core.entity.DelegatorInterface

import java.sql.Connection

def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)

String helperName = delegator.getGroupHelperName("default")

def sqlStmt = """

select count(*), customfield.id, customfield.cfname, customfield.description

from customfield left join customfieldvalue on customfield.id = customfieldvalue.customfield

where customfieldvalue.stringvalue is null

and customfieldvalue.numbervalue is null

and customfieldvalue.textvalue is null

and customfieldvalue.datevalue is null

group by customfield.id, customfield.cfname, customfield.description;;

"""

Connection conn = ConnectionFactory.getConnection(helperName)

Sql sql = new Sql(conn)

String result = """

<table>

  <tr>

    <th>Customfield Name</th>

    <th>Customfield Id</th>

  </tr>

"""

sql.eachRow(sqlStmt){ it ->

    result += """

        <tr>

          <td>${it.getAt("cfname")}</td>

          <td>${it.getAt("id")}</td>

        </tr>

"""

    }

return result+"</table>"

sql.close()
NSEU DevOps April 25, 2023

Thank you!

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2023

You're Welcome :)

Suggest an answer

Log in or Sign up to answer