Skip to content

Instantly share code, notes, and snippets.

@vikrantyadav11
Created August 15, 2024 15:13
Show Gist options
  • Save vikrantyadav11/a96215ecec157305c9caf7ede5a19476 to your computer and use it in GitHub Desktop.
Save vikrantyadav11/a96215ecec157305c9caf7ede5a19476 to your computer and use it in GitHub Desktop.
def fieldsResponse = get('/rest/api/2/field').asObject(List).body
def fieldCounts = [:]
fieldsResponse.each { field ->
def fieldId = field.id
def fieldName = field.name
def fieldType = field.schema?.type ?: 'N/A'
def jqlQuery
if (fieldId.startsWith('customfield_')) {
def customFieldId = fieldId.replace('customfield_', '')
jqlQuery = "cf[$customFieldId] is not empty"
} else {
jqlQuery = "$fieldId is not empty"
}
def searchResult = get('/rest/api/2/search')
.queryString('jql', jqlQuery)
.queryString('maxResults', 0) // We only need the count, not the actual issues
.asObject(Map)
.body
fieldCounts[fieldId] = [
name: fieldName,
type: fieldType,
count: searchResult.total
]
}
return fieldCounts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment