Forums

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

Script to fetch project keys

arielei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2025

Hello,

I need a script that based on a jql filter gives back output of unique project keys.

 

is this possible on DC 9.4.17?

 

Thanks,

Ariel

1 answer

1 accepted

4 votes
Answer accepted
Evgenii
Community Champion
September 25, 2025

Hi, @arielei 

There are 2 ways of making a script, that will match your requirements:
1. If you have ScriptRunner, you can make script in Groovy.
2. You can write script in Python and use REST API (it doesn't require any additional plugins)

Way 1 is easier, but requires plugin, way 2 is more universal. 

I can give you example of script, but I need to know, what solution to use.

arielei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2025

Thanks @Evgenii 

I have script runner, can you give an example of the script?

Evgenii
Community Champion
September 25, 2025

Great. 
You can use this script. Just modify JQL query

def issues = Issues.search('assignee = currentUser()')

def projectKeys = issues.collect { it.getProjectObject().key }.unique()
Like Chitra Nagdeo likes this
arielei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2025

 

Hey @Evgenii 

This does not work as its missing include params, i need some assistance with this. 

Evgenii
Community Champion
September 25, 2025

Describe your case please, what do you mean by missing input params?
Can you show me screen of error?

This script uses ScriptRunner HAPI functionality. It's in all actual versions of Scriptrunner. You just need to change JQL string.

String jql = "assignee = currentUser()"
def
issues = Issues.search(jql)
def projectKeys = issues.collect { it.getProjectObject().key }.unique()
log.warn(projectKeys)

ShareX_250925_315.png 

arielei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2025

Sure,

Screenshot 2025-09-25 at 13.12.40.png

Evgenii
Community Champion
September 25, 2025

Understood. Your scriptrunner version is not actual and doesn't support HAPI.

Then, try this code. It's made without HAPI usage

import com.atlassian.jira.config.IssueTypeManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser

List<MutableIssue> getIssuesByJQL(String jql) {
    IssueTypeManager issueTypeManager = ComponentAccessor.getComponent(IssueTypeManager.class)
    JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser) as JqlQueryParser
    SearchService searchService = ComponentAccessor.getComponent(SearchService)
    def techUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    Query query = jqlQueryParser.parseQuery(jql)
    SearchResults search = searchService.search(techUser, query, PagerFilter.getUnlimitedFilter())
    return search.results
}

// Get issues and extract unique project keys
def issues = getIssuesByJQL("assignee = currentUser()")
def projectKeys = issues.collect { it.getProjectObject().getKey() }.unique()
log.warn(projectKeys)
arielei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2025

Hey @Evgenii 

Thanks! that works!

Like Evgenii likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.17
TAGS
AUG Leaders

Atlassian Community Events