How can i use ScriptRunner for JIRA Cloud to find all issues i moved from Project A to Project B?

Josh Kronick June 7, 2018

We moved about 300 issues from Project A & C to Project B and forgot to attach components based on which projects they came from, so we need to find the issues that were moved in order to re-attach components.

 

i know previously, scriptrunner for JIRA Cloud didnt even exist, but now that it does, is it possible to use it to find the issues that were moved from Project A to Project B? or to find the previous issueKey ? rather than having to go through the history of each issue that was moved to find out which project it was moved from?

 

please help

 

Thanks,

 

Josh

1 answer

0 votes
Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2018

Hi,

this is a snippet from server, but maybe something like this will work on cloud too.

def String jqlQuery = 'project=B'
def fromProject1 = 'A'
def fromProject2 = 'C'

def result = ''

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def searchService = ComponentAccessor.getComponent(SearchService.class);
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

List<Issue> issues = null

def parseResult = searchService.parseQuery(user, jqlQuery);

if (parseResult.isValid()) {
def searchResult = searchService.searchOverrideSecurity(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues
}

issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll{it==~/$fromProject1.*/}.each{
result += "$it -> ${issue.key}, "
}
issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll(it==~/fromProject2.*/}.each{
result += "$it -> $(issue.key),"
)

Josh Kronick June 12, 2018

This is what it gives me in the script console when i copied and pasted your code snippet and input the projects..

 

im also not very savvy with scriptrunner, im not greatscript_console1.jpg with groovy, so any help would be GREATLY appreciated.

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2018

Hi,

sorry, had some typos in the script that I just fixed and added the imports, please try this again:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter

def String jqlQuery = 'project=B'
def fromProject1 = 'A'
def fromProject2 = 'C'

def result = ''

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def searchService = ComponentAccessor.getComponent(SearchService.class);
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

List<Issue> issues = null

def parseResult = searchService.parseQuery(user, jqlQuery);

if (parseResult.isValid()) {
def searchResult = searchService.searchOverrideSecurity(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues
}

issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll{it==~/$fromProject1.*/}.each{
result += "$it -> ${issue.key}, "
}
}

issues.each{ Issue issue ->
def oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
oldKeys.findAll{it==~/$fromProject2.*/}.each{
result += "$it -> ${issue.key},"
}
}
Josh Kronick June 13, 2018

for whatever reason, it only has a problem with those first 4 lines of "import" code... see screenshot.

 

Thanks for all your help.script_console_error_log.JPG

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2018

Does it work without the imports? Or does it complain then that it does not find the classes in the other lines?

Josh Kronick June 13, 2018

ok i thought i was getting somewhere, because it ran the query and looked like it was working, but then received this error...

 

see below:

 

script_console_error_log2.JPG

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2018

Hmm, thats because it does not find the class Issue, which was in the imports.

I am sorry, I don't know why it does not accept that import that way. This class is also still in the API-Reference.

Maybe someone else does have any idea on this.

Suggest an answer

Log in or Sign up to answer