Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Any way to access issue/project context from Custom Picker?

Oskar Austegard
Contributor
August 20, 2023

For a Custom Picker scripted field is there any way to access the issue or project context of the field, similar to the issue which is available in a standard scripted field?

The following code (or similar for an issue parameter) works fine in isolation but I can’t get it “connected” to the issue/project in the field. I could, possibly, set the project key as a parameter, but was hoping to avoid it

    /**
     * Filter a given project's list of components by locating components with a given {prefix}
     * @param descriptionPrefix The description prefix (inside the {})
     * @param project A project object whose components will be filtered (defaults to the ST project if null)
     * @return A filtered list of the project's components
     */ 
    static def filterComponentsByProject(String descriptionPrefix, Project project) {
        def projectManager = ComponentAccessor.getProjectManager()
        def componentManager = ComponentAccessor.getProjectComponentManager()

        project = project ?: projectManager.getProjectByCurrentKey("ST")

        def components = componentManager.findAllForProject(project.id).findAll {
            it.description?.startsWith("{${descriptionPrefix}}")
        }

        return components.collect {
            [
                value: it.id.toString(),
                displayName: it.name
            ]
        }
    }

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
August 21, 2023

Hi @Oskar Austegard

Could you please clarify, why are you doing this via the Custom Picker instead of using the Issue Picker?

Thank you and Kind regards,

Ram

Oskar Austegard
Contributor
August 21, 2023

I am looking to list a filtered set of Components, not issues

Suggest an answer

Log in or Sign up to answer