How to find issues that were moved from one project to another ....

Is there a way to find all issues? I can go in quick search and find one by one but that’s very tedious

How can I find all issues that were moved from project A to project B?

3 answers

1 accepted

As JQL history search does not support the project field this is not possible out of the box.

You can use Script Runner plugin and the following script to find all issues moved from project AAA to project BBB.

package eventim.scripts

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

jqlQuery = 'project = BBB'
fromProject = 'AAA'
result = ''

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

getFilterResult(jqlQuery,log).each{ Issue issue ->
    oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id)
    oldKeys.findAll{it==~/$fromProject.*/}.each{
        result += "$it -> ${issue.key}\n"
    }
}

return result

List<Issue> getFilterResult(String jqlSearch, log) {
    def searchService = ComponentAccessor.getComponent(SearchService.class);
    def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
    List<Issue> issues = null

    def parseResult =  searchService.parseQuery(user, jqlSearch);
    if (parseResult.isValid()) {
        def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
        issues = searchResult.issues
    } else {
        log.error("Invalid JQL: " + jqlSearch);
    }
    return issues
}

Henning

 

We have jira 4.4.5 running and also using Script runner plugin. Thank you for sharing the script to get the issues that are moved form project AAA to project BBB which is exectly what i am looking for. Appreciate if you could let me know the way to execute this script to get the result.

Henning Tietgens Community Champion Apr 22, 2013

You have to paste this script to into the script runner console, select Groovy as scripting engine and run the script.

Maybe you have to adapt the script for 4.4.5, I only tested it on 5.1.8.

Will this script impact other data if i execute on production?

Henning Tietgens Community Champion Apr 22, 2013

It's only reading information. Depending on the number of issues and your system it may decrease the performance of the system for a moment.

Best is, to try it on a test environment first.

is there an Oracle database query that can do the same thing?

Thanks a lot Henning!!! The script works absolutely great! You have just saved my day and most probably plenty of others too...

Regards,

Kishore Srinivasan

Hi Henning,

Thank you for sharing the script so that more people can benifit out of it.

But unfortunately I am getting below error when i try to run script for my projects

JIRA==> 6.4.13

Adaptavist Script Runner for JIRA Standard Edition==> 3.1.4

Error
startup failed: Script16.groovy: 12: unexpected token: issue @ line 12, column 43. ult(jqlQuery,log).each{ Issue issue -> ^ 1 error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script16.groovy: 12: unexpected token: issue @ line 12, column 43.
ult(jqlQuery,log).each{ Issue issue -&gt
^1 error

It would be great if you could provide any guidance related to this

Thanks a lot! 

Cheers!

Bhupesh

Henning Tietgens Community Champion Jul 17, 2017

There seems to be a conversion issue while this answer was transfered to the new community platform. I corrected the script, please try again with the corrected script.

Thanks,
Henning

Perfect!!

Thank you so much!

Now I'll work on adding it for multiple projects and write the output to a file since there is no way to store the results in script console.

 

Cheers!!

Bhupesh

Henning Tietgens Community Champion Jul 17, 2017

In the meantime the output format changed to html. I don't know if this was already the case in 6.4... maybe try to replace

result += "$it -> ${issue.key}\n"

with

result += "$it,${issue.key}<br>"

You'll get a comma separated list which could be copied out of the browser.


Thanks,
Henning

Thank you!

We are looking to automate this process like end user should be able to get list of tickets moved from project Ato B and B to A with a button click somewhere in UI in JIRA.

So thinking to put the results in a custom field and put the script in post functions.

 

Cheers!,

Bhupesh

Henning Tietgens Community Champion Jul 17, 2017

If you want to use a postfunction you could write the result to the issue as a comment.

if (transientVars.keySet().contains('comment')) {
result+= "\n" + (transientVars.comment as String)
}
transientVars.comment = result

 In this case there should not be any html code in result.

That's really cool.

Can we write it to a custom field? Maybe count of ticket also which moved from A to B and B to A?

 

 

Henning Tietgens Community Champion Jul 18, 2017

You can get the count by using 

oldKeys.findAll{it==~/$fromProject.*/}.size()

And of course this could be written to a custom field, see https://developer.atlassian.com/jiradev/jira-platform/guides/issues/guide-performing-issue-operations

I see this issue is very old. Has JQL been updated to be able to handle cases like this? We are on the cloud version and do not have script runner. 

I am also interested in learning about how we can query for issues that have moved from one project to another and I don't have a script runner.

The JQL Tricks Plugin seems to have a function to return moved tickets.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

93 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you