You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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