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
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),"
)
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 great with groovy, so any help would be GREATLY appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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},"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for whatever reason, it only has a problem with those first 4 lines of "import" code... see screenshot.
Thanks for all your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does it work without the imports? Or does it complain then that it does not find the classes in the other lines?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.