Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,847
Community Members
 
Community Events
168
Community Groups

How to find all custom fields that are on zero screens?

Edited

Hello ,

Im fairly new to groovy script and the jira api

im trying to write a script  to return all custom field that are on 0 screens .

any ideas how to do so? or which classes / methods are relevant for this?

 

any help will be greatly appreciated.

  

 

1 answer

0 votes
Tom Lister Community Leader Oct 21, 2018

Hi Yotam

if this is just a one off task, then the custom fields page will show the screens used column. Although just because a field is not on a screen doesn’t mean it isn’t in use in a script or workflow.

Hi,

I know i can find fields with no screen on the custom fields page but with 1500+ fields this means a lot of manual work,of which I'm trying to avoid.

and also its a task I need to do on a monthly basis.

Tom Lister Community Leader Oct 22, 2018

Hi Yotam

are you able to run SQL in the JIRA db?

this MySQL query should show screens used by fields and count of custom values present or nulls if unused

SELECT DISTINCT
cf.id,
cf.cfname AS field,
cfu.screenname,
cfu.tabname,
fvals.num_values
FROM
customfield cf
LEFT JOIN
(SELECT
cfi.id,
cfi.cfname,
fs.name AS screenname,
fst.name AS tabname,
fsli.fieldidentifier AS fieldid
FROM
fieldscreen fs, fieldscreenlayoutitem fsli, fieldscreentab fst, customfield cfi
WHERE
fst.fieldscreen = fs.id
AND fsli.fieldscreentab = fst.id
AND REPLACE(fsli.fieldidentifier, 'customfield_', '') = cfi.id) cfu ON cf.id = cfu.id
LEFT JOIN
(SELECT
customfield, COUNT(*) AS num_values
FROM
customfieldvalue
GROUP BY customfield) fvals ON cf.id = fvals.customfield

Hi

thanks for the answer, its useful for different stuff but still need to be able to find custom fields that have 0 screens , this data obviously exists somewhere in the database but I can't find a way to query it.

 

if you have any suggestions on how to do that , I will be forever grateful. 

Thanks anyway!

Tom Lister Community Leader Oct 23, 2018

Hi Yotam

the query should show null for screen name against fields that are not in any screens. Could include it in view or inline query to return just those rows with no screens. The num values should indicate fields that have had values set at some time.

Hi! thanks for the help, i managed to get it to work, but I found a simpler way to do it with script. just two loops . putting it here in case its useful to anyone.


CustomFieldManager oo = ComponentAccessor.getCustomFieldManager()
List<CustomField> kk = oo.getCustomFieldObjects();

Logger o = Logger.getLogger("sid")
FieldScreenManager SM = ComponentAccessor.getFieldScreenManager()
FieldScreen FS = SM.getFieldScreen(f)

Collection<FieldScreen> FSO = SM.getFieldScreens()
List<FieldScreen> FSO2 =FSO.toList()
int counter1 = 0;
int zeroscreens =0;
try{
while(counter1 <kk.size()){
int counter2 = 0
while(counter2 <FSO2.size()){
if(FSO2.get(counter2).containsField(kk.get(counter1).getId())){
counter1++
counter2 = 0
}else{
counter2++

}
if(counter2 == FSO2.size()-1 && FSO2.get(counter2).containsField(kk.get(counter1).getId())== false ){
o.error(kk.get(counter1).getName())
counter1++
zeroscreens++
}
}


}

}catch(IndexOutOfBoundsException) {
o.error("Done")
o.error(counter1 + " fields scanned " +zeroscreens + " fields with 0 screens found")


}
Like Tom Lister likes this

Hi @yotam abt

Are you still using this script? Maybe you have an updated version of it (some of the methods are deprecated)?

Thanks 

@David Antebi 

 

Hi,

I'm not working as a Jira admin for quite some time :)

This script is really not my best work but it worked when I used it.

 

what methods are giving you trouble? maybe I could try to rewrite it for you quickly.

This works for me on Server


 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.application.ApplicationKeys

import com.atlassian.jira.application.ApplicationAuthorizationService

 

def oo = ComponentAccessor.customFieldManager

def kk = oo.getCustomFieldObjects()

def o = ComponentAccessor.worker

def SM = ComponentAccessor.fieldScreenManager

def FS = SM.getFieldScreens()

 

def FSO = SM.getFieldScreens()

def FSO2 = FSO.toList()

 

def sb = new StringBuilder()

 

int counter1 = 0;

int zeroscreens =0;

try{

  while(counter1 <kk.size()){

      int counter2 = 0

      while(counter2 <FSO2.size()){

        if(FSO2.get(counter2).containsField(kk.get(counter1).getId())){

            counter1++

            counter2 = 0

        }

        else{

          counter2++

        }

        if(counter2 == FSO2.size()-1 && FSO2.get(counter2).containsField(kk.get(counter1).getId())== false  ){

          sb.append(kk.get(counter1).getName()+"\n")

          counter1++

          zeroscreens++

        }

      }

  }

}

catch(IndexOutOfBoundsException) {

sb.append("Done\n")

sb.append(counter1 + " fields scanned " + zeroscreens + " fields with 0 screens found")

}

 

return sb.toString()

Suggest an answer

Log in or Sign up to answer