Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner Custom Script field Multi-picker

Creating a Jira screen for new users requests. I need to create a field that is multi-picker that lists the current Jira projects, so the person requesting the account can pick which projects they need access to, and populate the ticket accordingly.

I am certainly not a programmer and I can't find anything out there like this.

Any help appreciated

Thanks,

Matt

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 26, 2022

You can create a scriptrunner script field using the "Custom Picker" option.

Using the "Show Snippet", I grabbed the example for Version picker, and converted the suggested configuration code to make it work as a project picker:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
import org.apache.commons.lang3.StringUtils

def projectManager = ComponentAccessor.projectManager

validate = { Project project ->
!project.archived
}

search = { String inputValue ->
projectManager.projectObjects.findAll {
!it.archived && (StringUtils.containsIgnoreCase(it.name, inputValue) | StringUtils.containsIgnoreCase(it.key, inputValue))
}
}

getItemFromId = { String id ->
projectManager.getProjectObj(id.toLong())
}

toOption = { Project project, Closure highlight ->
new PickerOption(
value: project.id.toString(),
label: "$project.name ($project.key)",
html: "${highlight(project.name, false)} (${project.key}) ${getLozenge(project)}",
)
}

renderItemViewHtml = { Project project ->
"$project.name ($project.key) ${getLozenge(project)}"
}

renderItemTextOnlyValue = { Project project ->
"$project.name ($project.key)"
}

String getLozenge(Project project) {
if (project.isArchived()) {
'<span class="aui-lozenge aui-lozenge-subtle">Archived</span>'
} else {
'<span class="aui-lozenge aui-lozenge-current aui-lozenge-subtle">Active</span>'
}
}

You can find more details in the documentation: https://docs.adaptavist.com/sr4js/6.58.1/features/script-fields/built-in-script-fields/custom-picker?utm_source=product-help

Thanks for this, Peter.  Do you know of any concise documentation that clearly communicates the functions that are expected to be implemented in a configuration script?

The ? button for the configuration screen shows that the following are accessible, but it is not clear which may be required for an implementation

log
multiValueDelimiter
allowJavaScript
maxRecordsForSearch
highlightMatchesWordPrefixesOnly
disableTextIndexing
getPlaceholderString
renderViewHtml
renderColumnHtml
renderTextOnlyValue
search
validate
getItemFromId
toOption
renderItemViewHtml
renderItemColumnViewHtml
renderItemTextOnlyValue


Notably absent is `issue` which is available in a simple scripted field.

My use case is to access (a subset of) Components in the current project, which would be doable if I could find a way to refer to the current issue/project/component list

I find the Adaptivist documentation to be frantically dispersed... 

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 21, 2023

I'm not aware of any documentation other than the page I shared above.

But based on that, the "issue" variable is only defined in the context of the search method you see in the '?' popup.

So if you want to get a filtered subset of components, you can set the configuration script to:

search = {String inputValue, Issue issue->
  def projectComponents = ComponentAccessor.projectComponentManager.findAllForProject(issue.project.id)
  return projectComponents.findAll{ <filter criteria for your subset>}
}

Suggest an answer

Log in or Sign up to answer