Hello Everyone,
I would like to know how can I use Script Runner to get all "Assignee" from the JQL query?
My JQL query sample is:
project = "project_name" AND "custom_field" = value AND status not in (Closed) AND assignee changed ON 2020-10-05"
After that I will need to update all the Assignee field to the original User assigned before the the changed date. I have tried testing some of the solved cases here in Community, but its not working on my end. can you give me an example code or guide that I can follow?
Thank you.
Thanks for checking in this issue. Here is my tested code which is working but does not fully get my requirements.
JQL is achieve but I wanted to display the results of Assignee of those tickets and once it shows the list I can issue another script to update the Assignee of those issues which I will issue in another server.
Jira Server is running version 8.5.4 and scrip runner version 6.7.0 .
I have this references from Adaptavist Library:
Bulk Update the Value of a System Field on Jira Issues
Perform a JQL Search in ScriptRunner for Jira
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
// Set log level to INFO
log.setLevel(Level.INFO)
// The JQL query you want to search with
final jqlSearch = "project = \"Documentation Status\" AND status not in (Closed) AND assignee is EMPTY ORDER BY status DESC"
// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.isValid()) {
log.error('Invalid query')
return null
}
try {
// Perform the query to get the issues
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results
issues.each {
log.info(it.key)
}
issues*.key
} catch (SearchException e) {
e.printStackTrace()
null
}
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
instead of it.key try the following
or display along with the issue key like this.
log.info(it.key + "," + it.assignee.username)
I hope it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great it is working! where can I get those definitions you have given? can you provide a link please?
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
// Set log level to INFO
log.setLevel(Level.INFO)
// The JQL query you want to search with
final jqlSearch = "project = \"Documentation Status\" AND status not in (Closed) AND assignee is EMPTY ORDER BY status DESC"
// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.isValid()) {
log.error('Invalid query')
return null
}
try {
// Perform the query to get the issues
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results
issues.each {
log.info(it.assignee.username)
log.info(it.key)
}
issues*.key
} catch (SearchException e) {
e.printStackTrace()
null
}
I tested it on my personal sandbox but when I run it to our server-uat, I got an error I think maybe because I have 400+ tickets/issues on that query.
Advanced Logging which part of the documentation am I going to implement so I can view the logs?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def sb = new StringBuilder()
sb.append("Text")
sb.append("More Text")
return sb
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For my last question. What is the best way of automating my script to update the assignee of base on the JQL queries which consist of multiple JQL queries and Assignees?
I have tried using searchQuery1, searchQuery2 but it is not working. below is my code.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.search.SearchQuery
// The issues returned from that JQL will get altered
//final searchQuery = "project = PX AND \"Custom Field Name\" ~ \"custom field value\" AND status not in (Closed) AND assignee changed ON 2020-10-05"
final searchQuery = "project = \"Project\" AND issuekey = \"ISSUE-KEY1\""
final searchQuery = "project = \"Project\" AND issuekey = \"ISSUE-KEY2\""
final searchQuery = "project = \"Project\" AND issuekey = \"ISSUE-KEY3\""
final searchQuery = "project = \"Project\" AND issuekey = \"ISSUE-KEY4\""
final searchQuery = "project = \"Project\" AND issuekey = \"ISSUE-KEY5\""
// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueService = ComponentAccessor.issueService
// Perform the search
def query = jqlQueryParser.parseQuery(searchQuery)
def searchResults = searchProvider.search(SearchQuery.create(query, loggedInUser), PagerFilter.unlimitedFilter)
// Iterate all the results to update each issue
searchResults.results.each { documentIssue ->
// Define the new params (a new description)
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setAssigneeId("Username1") //Username
issueInputParameters.setAssigneeId("Username2") //Username
issueInputParameters.setAssigneeId("Username3") //Username
issueInputParameters.setAssigneeId("Username4") //Username
issueInputParameters.setAssigneeId("Username5") //Username
// Update the issue
def issueId = documentIssue.document.fields.find { it.name() == "issue_id" }.stringValue().toLong()
def updateValidationResult = issueService.validateUpdate(loggedInUser, issueId, issueInputParameters)
assert updateValidationResult.isValid() : updateValidationResult.errorCollection
// Validate the update
def issueResult = issueService.update(loggedInUser, updateValidationResult)
assert issueResult.isValid() : issueResult.errorCollection
}
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.