You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I'm trying to create a single select list with a list of the active projects with my Jira instance. There are around 60 projects at the moment, and they all have unique names/keys. So far, I've tried using scriptrunner to create a scripted field, but when that didn't work I moved onto a behaviour instead. Ideally, I would want this field to update itself whenever a user interacts with it, and I want to pull this information directly from Jira itself. My team do not use the built-in archiving process in Jira, instead, we assign it to an archived permission scheme, as you can see in the code below.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def cfManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def permSchemeManager = ComponentAccessor.getPermissionSchemeManager()
def prjManager = ComponentAccessor.getProjectManager()
final singleSelectName = 'Project Name'
def singleSelectField = cfManager.getCustomFieldObjectsByName(singleSelectName)[0]
def formSingleSelect = getFieldByName(singleSelectName)
def config = ComponentAccessor.fieldConfigSchemeManager.getRelevantConfig(issueContext, singleSelectField);
def options = optionsManager.getOptions(config)
def arch = permSchemeManager.getSchemeObject("Archived Permission Scheme")
def archivedPrjs = permSchemeManager.getProjects(arch).toArray()
def archivedPrjSize = archivedPrjs.size()
for (int i = 0; i < archivedPrjSize; i++) {
archivedPrjs[i] = archivedPrjs.getAt(i).toString().split(':')[1].substring(1)
}
def projects = prjManager.getProjects().toArray()
def projectsSize = projects.size()
for (int i=0; i<projectsSize;i++){
def currentPrjKey = projects.getAt(i).toString().split(':')[1].substring(1)
projects[i] = prjManager.getProjectByCurrentKey(currentPrjKey).name
}
for (int i = 0; i < archivedPrjSize; i++) {
for (int j = 0; j < projectsSize; j++) {
if (archivedPrjs[i] == projects[j]) {
projects[j] = null
}
}
}
projects.sort()
for (int i = 0; i< archivedPrjSize; i++) {
projects = projects.tail()
}
projectsSize = projects.size()
def projectsMap = projects.collectEntries( {
[(projects.getIndices()):(projects)]
})
formSingleSelect.setFieldOptions(projectsMap)
Can someone suggest a better way to do this, as I am currently stumped as to the best solution?
Many thanks,
Harry
Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events