Display previous key of moved issue

Mark Bednarski March 13, 2013

Hi

I need to migrate several projects into one. Now I have two problems I didn't find an answer for.

1. How can I display the old key on the viewing screen of my issues?

2. Can I create a JQL query which reports me the old key in a column so we can produce reports containing the old and the new key during transition phase.

Thanks a lot
Mark

6 answers

1 accepted

7 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.
March 14, 2013

You can also write a little script for a scripted field, provided by Script Runner plugin, to display a previous issue key.

return componentManager.changeHistoryManager.getPreviousIssueKeys(issue.id)?.join(', ')

You can use this field to display the old key in the issue view an in the issue navigator.

Henning

Mark Bednarski March 14, 2013

Great, this was what I was really looking for.

For those who are unexperienced like me this is what you need to do:

# Install Script runner plugin

# Create cusom field of "scripted field" type

# Go to plugins scripted fields and add Henning's script there

Thank you!

Deleted user April 14, 2015

Perfect! Thanks Henning and Mark. This is exactly what I needed.

Prasad Kawadkar October 16, 2020

Hi Mark and Henning,

I am getting an error when I am trying to create a scripted field through this plugin.

error 1.JPG

Could you help?

 

Best,

Prasad

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.
October 16, 2020

Hi Prasad,

Are you using Jira Cloud? The script is for Jira Server only.

Best,

Henning

Prasad Kawadkar October 19, 2020

Hi Henning,

Thanks for clarifying.

Yes, I am using JIRA Cloud.

Do you have any solution for this issue on the Cloud instance?

 

Best,

Prasad

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.
October 19, 2020

No, unfortunately not. I only have minimal experience with Jira Cloud.

Best, Henning

4 votes
Cameron Jeffries November 2, 2018

It would be very helpful to be able to do with JQL, since the links exist in the database!

4 votes
Deleted user September 25, 2015

Henning has it correct, but the API that was being used is now depreciated. So, I have updated it to use the new getAllIssueKeys method. Also if you return null, the field won't show up on non-moved tickets.

 

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;

IssueManager issueManager = ComponentAccessor.getIssueManager();
Set<String> tickets = issueManager.getAllIssueKeys(issue.id)
tickets = tickets.minus(issue.key)
if (tickets.isEmpty()) {
   return null
}
return tickets.join(', ')
Rathna August 30, 2017

Hi Dan,

I know that I am trying to trigger / open an very old Question / Answer. After implementing this in JIRA, I would like to know how to search for the values that are stored in this field using JQL.

Thanks in advance.

Nick Rusman September 6, 2019

This doesnt work anymore:

 

2019-09-06 11:53:56,478 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2019-09-06 11:53:56,478 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created groovy.lang.MissingPropertyException: No such property: lt for class: Script92 at Script92.run(Script92.groovy:5)

Joe Harmon October 7, 2019

I got the same error and changed it to the following and it worked for me.

import com.atlassian.jira.issue.IssueManager;
IssueManager issueManager = ComponentAccessor.getIssueManager();
tickets = issueManager.getAllIssueKeys(issue.id)
tickets = tickets.minus(issue.key)
if (tickets.isEmpty()) {
return null
}
return tickets.join(', ')

wangdanfeng June 4, 2020

import com.atlassian.jira.issue.IssueManager;import com.atlassian.jira.component.ComponentAccessor
IssueManager issueManager = ComponentAccessor.getIssueManager();tickets = issueManager.getAllIssueKeys(issue.id)tickets = tickets.minus(issue.key)if (tickets.isEmpty()) {return null}return tickets.join(', ')

1 vote
Shawna Morris February 14, 2020

The latest script didn't work for me. I just re-worked it and have this script pulling the previous issue key(s) and displaying that in a custom scripted field. 

Pre-Requisite:

PR1. ScriptRunner for JIRA

Updated Script:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;

def IssueManager issueManager = ComponentAccessor.getIssueManager();
def tickets = issueManager.getAllIssueKeys(issue.id)

tickets = tickets.minus(issue.key)
if (tickets.isEmpty()) {
return null
     }
return tickets.join(', ')
Rich Barron February 14, 2020

Actually just tried this on Jira cloud and received: 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 2: unable to resolve class com.atlassian.jira.issue.IssueManager @ line 2, column 1. import com.atlassian.jira.issue.IssueManager; ^ Script1.groovy: 1: unable to resolve class com.atlassian.jira.component.ComponentAccessor @ line 1, column 1. import com.atlassian.jira.component.ComponentAccessor; ^ 2 errors at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:51) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:32) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:29) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)

Shawna Morris February 14, 2020

We use JIRA Server. So, I'm not sure if the code needs to be different. Attached images on how the script looks in "Fields" in ScriptRunner and how it appears on the Issue Screen (Server 7.10.1)

previousKey_JIRA.PNGpreviousKey_Script.PNG

Like Shailesh Dhawale likes this
Rich Barron February 14, 2020

Thanks. I did read where Jira server and Jira cloud are pretty different on how they handle these scripts so I will keep looking. But this was a great start. Thanks for the help Shawna!

Mithil November 6, 2020

Hi Shawna, I tried your code, It is working but getting additional issue key also not sure how? I don't have those project too. and also key is repeating.

Fernando Pizzabiocche March 4, 2021

Thank you  @Shawna Morris , your script continues to provide accurate information on March, 2021.

1 vote
Andreas Viklund October 6, 2013

Is it possible to achieve the same functionality on Jira OnDemand since it is not possible to use Script Runner??

1 vote
Jobin Kuruvilla [Adaptavist]
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 13, 2013

You can see the old key in the change history tab of an issue. If you need to capture it anywhere else, you will have to implement a listener and store the value in a read only custom field.

Storing in custom field is required even to display the key in issue navigator, no matter what JQL you use.

Mark Bednarski March 14, 2013

Hi Jobin

Sounds great, but what you mean by "implement a listener"?

Thank you!

Mark

Jobin Kuruvilla [Adaptavist]
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 14, 2013

Suggest an answer

Log in or Sign up to answer