Hello,
I often need to create similar tickets which are based on a query result.
Example:
Is there an existing plugin for such a task?
Hi Robert,
If you are willing to user a 3rd party plugin, what you are asking is doable using ScriptRunner for JIRA (link to documentation) There is also a free version 3.1.4 - which is only available for JIRA v6 (check version history). So what you could do with the tool is to navigate to script console and run the script below.
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.issue.IssueInputParametersImpl import com.atlassian.jira.project.Project import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.web.bean.PagerFilter def jqlSearch = """ project = "Source Project" """ def PROJECT_KEY_TO_COPY_TO = "TP" def issueManager = ComponentAccessor.getIssueManager() def searchService = ComponentAccessor.getComponent(SearchService) def targetProject = ComponentAccessor.getProjectManager().getProjectObjByKey(PROJECT_KEY_TO_COPY_TO) def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issues = [] SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch) if (parseResult.isValid()) { def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) } } //iterate through the issues returned from the JQL and create clone issues to project with key PROJECT_KEY_TO_COPY_TO issues.each { it -> createIssue(targetProject, it, user) } /** * A function to create the target issue based on target project and properties extracted by the source issue. * You can build the target issue in the way you want (issueType, assignee, reporter, customFields etc..) * but for the example, for the mandatory fields (issueType, project) and for the highly recommended * (reporter, priority) we copy the source issue's ones * @param targetProject A target Project with key PROJECT_KEY_TO_COPY_TO * @param sourceIssue The source issue where from the summary (and any other properties) will be copied */ def createIssue(Project targetProject, Issue sourceIssue, ApplicationUser user) { def issueService = ComponentAccessor.getIssueService() // build the target issue's summary def targetIssueSummary = "Test ${sourceIssue.key} - ${sourceIssue.summary}" IssueInputParameters issueInputParameters = new IssueInputParametersImpl() issueInputParameters .setProjectId(targetProject.id) //use the mandatory target project id .setSummary(targetIssueSummary)//use the mandatory issue summary .setIssueTypeId(sourceIssue.issueTypeId) //use the mandatory source issue's issueType (make sure that the target project has this issue type configured) .setReporterId(sourceIssue.reporterId) //use the source issue's reporter .setPriorityId(sourceIssue.priority.id) //use the source issue's priority //set any other fields you wish for the new issue IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters) if (createValidationResult.isValid()) { def targetIssue = issueService.create(user, createValidationResult).issue log.debug "Target issue ${targetIssue.key} created with summary ${targetIssue.summary}" } }
The sciprt above is tested in a JIRA v7 instance, if you need it tfor a JIRA v6 then there should be a couple of trivial changes
regards, Thanos
Hey Robert,
This is something new. You can refer the following discussions:
https://answers.atlassian.com/questions/90304
BR,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.