Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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 Champion
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 Champion
April 25, 2023

You're Welcome :)

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events