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
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.
Thanks @Evgenii
I have script runner, can you give an example of the script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great.
You can use this script. Just modify JQL query
def issues = Issues.search('assignee = currentUser()')
def projectKeys = issues.collect { it.getProjectObject().key }.unique()
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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.