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

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2013

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?

5 answers

1 accepted

13 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2013

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.

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

 

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2013

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 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.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2013

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

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 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.

KP11
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2013

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

Kishore Srinivasan December 11, 2013

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

Bhupesh Nagda July 17, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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

Bhupesh Nagda July 17, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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

Bhupesh Nagda July 17, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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.

Bhupesh Nagda July 18, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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

Michael Schultz March 19, 2019

@Henning Tietgens Any chance you can help me modify the code above to look at issues moved from any project? Instead of needing an individual Project Key

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2019

Sure, you could use this.

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

def jqlQuery = 'project = BBB'
def result = ''

def issueManager = ComponentAccessor.issueManager

getFilterResult(jqlQuery,log).each{ Issue issue ->
def allOtherKeys = issueManager.getAllIssueKeys(issue.id)?.findAll{it != issue.key}
if (allOtherKeys?.size() > 0) {
// The issue had another key than the current one
result += "${allOtherKeys.join(", ")} -> ${issue.key}<br>"
}
}

return result

static 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
}

You have to adapt the jqlQuery string to select the issues you want to inspect for moved ones.

Henning

Michael Schultz March 20, 2019

@Henning Tietgens Thank you!

Aaron Andrade May 2, 2019

@Henning Tietgens This is perfect as to what I need, unfortunately I am getting an error with this snippet

WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingPropertyException: No such property: issues for class: com.atlassian.jira.issue.search.SearchResults at Script66.getFilterResult(Script66.groovy:29) at Script66$getFilterResult.callStatic(Unknown Source) at Script66.run(Script66.groovy:11)

 I did replace "BBB" with a legitimate project, otherwise I haven't made any modifications.  I am on JIRA 8.0.2 (Server Side) and 5.5.3.1-jira8 of ScriptRunner.

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2019

I think for Jira 8 you have to replace searchResults.issues by

searchResults.results

Like Tom H likes this
Aaron Andrade May 3, 2019

Thanks @Henning Tietgens helps to look at the upgrade 8 notes, bad on my part!  Ok... one last thing I am struggling with is the log.error().  I'm getting "Cannot find matching method."  I see we are passing it, but for whatever reason it doesn't recognize it.   If I put log.error above the static line (obviously replacing jqlSearch), it works.

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2019

I think this is only an error for the console. If you run the script it shouldn't be a problem. If you want, you could add 

import org.apache.log4j.Logger

and define the type for log

static List<Issue> getFilterResult(String jqlSearch, Logger log) {

to get rid of the error in the console.

Aaron Andrade May 6, 2019

Thank you.... I had tried the import and even tried defining the type... I erroneously defined it as "Log log" and not "Logger log".   Ugh.  Thank you so much for your quick response!   I think we are sailing now!

Saurabh_Malik May 17, 2020

Thanks, @Henning Tietgens  for this wonderful script. Is there a way to get a date along with the ticket number when it is moved from project A to Project B. 

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2020

Yes, you have to analyze the change history items for each issue found (ComponentAccessor.changeHistoryManager.getAllChangeItems(issue)) to find the change of the issue key. From this change you can get the date (changeItem.created).

OSTechAdmin May 19, 2020

Thanks @Henning Tietgens for your response. I am not a coder - so could you please help me how to append these parameters within your script. 

 

I will appreciate your help.

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2020

I don't think it's a good idea to use these scripts without any knowledge of what's going on.

Just try it, it's not that difficult. Try to get something working in Groovy and come back with specific questions.

Or hire somebody to code and maintain these scripts for you.

All these scripts have to be maintained, especially for Jira upgrades, they have to be tested and updated because of API changes.

Don't understand me wrong, I like to help, but not for "Please code for me" questions.

OSTechAdmin May 20, 2020

Correctly said. Thanks.

Abhay Patil April 8, 2022

If the initial and destination projects use different sets of status' then one can figure what moved from project A to Project B.

E.g. if project A always uses a status = review before the issue is moved to project B, where "review" status is not used, then the following query will find all the issues in project B that have project A pedigree.

project = B and status was in (review)

This will not find issues that were created in Project B (and not moved from Project A).

Mathankumar Manibala June 29, 2022

Hi @Henning Tietgens

Could you please explain the project declaration?

For example: "jqlQuery = 'project = BBB'
                       fromProject = 'AAA'
                       result = ''

What is the  'project = BBB'  fromProject = 'AAA'? Is It project ID or project name?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2022

Hi,

jqlQuery is a query like you would enter in issue search in advanced mode. This could be project = <PROJECT KEY> or <PROJECT ID> or <PROJECT NAME>. This query should find all issues where you want to know which are moved from "fromPrjoect".

fromProject is a project key (technically it's the start of the issue key). This is the previous project of the issues.

Best regards,
Henning

4 votes
Dale Bosserman January 25, 2018

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. 

Angela Goodwin February 15, 2018

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.

Saurabh Malik May 16, 2020

Thanks, @Henning Tietgens for this wonderful script. Is there a way to get a date along with the ticket number when it is moved from project A to Project B. 

1 vote
Alejandro Conde Carrillo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2013

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

Saurabh Malik May 16, 2020

Does it return move date as well? 

0 votes
AB January 25, 2022

Hi, this is a fantastic thread!

When I try to run this script with the modification I get an error - how can I fix that (see below). And an additional question - how can I change the script to show issues which were moved from one ticket type to another within the same project?

Thanks!


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

def jqlQuery = 'project = BBB'
def result = ''

def issueManager = ComponentAccessor.issueManager

getFilterResult(jqlQuery,log).each{ Issue issue ->
def allOtherKeys = issueManager.getAllIssueKeys(issue.id)?.findAll{it != issue.key}
if (allOtherKeys?.size() > 0) {
// The issue had another key than the current one
result += "${allOtherKeys.join(", ")} -> ${issue.key}<br>"
}
}

return result

static 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 = searchResults.results
} else {
log.error("Invalid JQL: " + jqlSearch)
}
return issues
}


Error

The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script90.groovy: 29: Apparent variable 'searchResults' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'searchResults' but left out brackets in a place not allowed by the grammar. @ line 29, column 18. issues = searchResults.results ^ 1 error </pre>.

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 25, 2022

Hi, there is one s to much on the end of searchResult. Without it the code should be ok.

For issue type changes you have to analyze the issue history (change items) like for the change date above.

Best regards,
Henning

Like AB likes this
0 votes
sushanta August 24, 2018

Hi Henning,

Its working fine if there are few number of issues are moved from the project.
But I'm getting an error while checking more issues those are moved from one project to another project . "Error timeout : No Stack Trace available."
Any way to fixed this issue ?

 

Thanks,

Sushanta

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2018

Hi Sushanta,

in this case you have to replace the "result +=" with "log.error " to write the output to the atalassian-jira.log file. This will continue, even if the UI reports a timeout. Additionally I would add a line "log.error "Done." before the line "return result", to see in the log file when the script is done.

Henning

sushanta August 27, 2018

 

 

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2018

Yes, you will get the timeout error, but the script will continue to run in background. Because in this case you don't see the result of the script, the result should be printed to the atlassian-jira.log file.

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

log.error "Done."
return result

You can view the location of the atlassian-jira.log in the 'File Paths' section of the Jira system information page.

Henning

sushanta August 27, 2018

Hi Henning,

Thanks for your quick response.The work around is working fine. Now I'm able to see the results in catalina.out . 

Thanks a lot Henning!!! 

Thanks

Sushanta

accountspayable November 1, 2018

How would I filter my results by last 30 days?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2018

What last 30 days? Created?

sushanta November 4, 2018

accountspayable@omahasteaks.com

You can modify the JQL like : jqlQuery = 'project=XXX and issuetype=XXX AND created >= 2018-10-01 AND created <= 2018-10-31'

Veeraj Bissoonauth October 16, 2019

Hi There, Has anyone tried this on JIRA cloud ?

Like # people like this
Ashish_Kanaparthi January 21, 2020

Hi @Veeraj Bissoonauth  Did you find any solution for this?

Veeraj Bissoonauth January 21, 2020

We tried Postman, and were able to pull the raw data. 

However, the challenge we came across is the following:

Say issue AAA-123 is moved from project AAA to project BBB, and the new issue # is BBB-345;

We are not able to pull any historical data from project AAA for the issue AAA-123; we have to pull data from project BBB. For the issue BBB-345, we can see that it was moved from project AAA, and the id was AAA-123.

Is there a was for us to pull the move related from AAA ?

 

Thank  you,

 

Veeraj

Suggest an answer

Log in or Sign up to answer