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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan,
I have created a component picker field as shown below. But it doesn't work. Can you please help me in that regard.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure what you were trying to do with that code, but it was a bit of a mess.
This here should get you something that works and you can adjust the render options:
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
def componentManager = ComponentAccessor.projectComponentManager
search = { String inputValue, Issue issue ->
def components = componentManager.findAllForProject(issue.projectObject.id)
return components
}
getItemFromId = { String id ->
componentManager.getProjectComponent(id.toLong())
}
toOption = { ProjectComponent component, Closure highlight ->
new PickerOption(
value: component.id.toString(),
label: component.name,
html: "${highlight(component.name, false)}"
)
}
renderItemViewHtml = { ProjectComponent component ->
getLozenge(component)
}
renderItemTextOnlyValue = { ProjectComponent component ->
component.name
}
String getLozenge(ProjectComponent component) {
{
"""<span class="aui-lozenge aui-lozenge-current aui-lozenge-subtle">$component.name</span>"""
}
}
Project getProject(ProjectComponent component) {
def projectManager = ComponentAccessor.projectManager
projectManager.getProjectObj(component.projectId)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.