Hello Community,
using Scriptrunner I want to create a scheduled job, where at a certain date (once a year) a jql is searching for issues from the issuetype A. For every found issue I want to create a new Issue, of the issuetype B, and copy some information like assignee and the values of some customfields.
I know how to use the jql and get a list of the issues but I dont know how I shall continue...
Thankful for your help!!
https://library.adaptavist.com/entity/create-a-backdated-issue is a sample of a really basic "create single issue with some data", you should be able to use that inside an iterator (iterating over your list of issues), and adding copied fields from it should be easy (have a rummage around the rest of the library for examples of working with custom fields)
Ok, thanks for your advice @Nic Brough -Adaptavist- .
I tried to use this inside a for loop (as iterator), bacause I am very unexperienced I am not sure if I am doing it right.
Is that the way you ment it?
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
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
// Set log level to INFO
log.setLevel(Level.INFO)
// The JQL query you want to search with
final jqlSearch = "issuetype = 'SUD Modul Basic' and 'Sommersemester aktiv?' = aktiv"
// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.valid) {
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)
}
// ITERATOR --> create new isse
for (i in issues){
def project = ComponentAccessor.projectManager.getProjectObjByKey("SUD")
if (project){
MutableIssue issue = ComponentAccessor.issueFactory.issue
issue.projectObject = project
issue.issueType.name == "SUD Modul"
issue.summary == "SoSe ${now.format("yyyy")} ${issue.Studiengang}-${issue.Modulkennung}"
ComponentAccessor.issueManager.createIssueObject(user, issue)
}
}
} catch (SearchException e) {
e.printStackTrace()
null
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's how I would do it.
I'm not 100% sure of your code, I don't do a lot of coding and have to look stuff up all the time when I do, so I can't validate it. But you've definitely got the structure right, and it does look like it should work.
(I would change one little thing - I'd move the "if project" check way up the script - there's little point in checking if the same project exists for every single create issue call, I'd just end the script before doing anything else)
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.