With Automation for Jira how do we access the previous key value of a moved issue?

Cédric Cox
Contributor
October 21, 2020

Hi everyone,

 

I'm dealing with the trigger "Issue moved" in JIRA Automation. I need to retrieve the previous key value of the moved issue. The only key I can get now is the new key (corresponding to the new project). Any guess? I try {{movedIssue.key}} without any hope, but this is not working.

Thanks,

 

Cédric

2 answers

1 accepted

0 votes
Answer accepted
Bill Sheboy
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 21, 2020

Hi @Cédric Cox 

Are you trying to get the moved issue's prior key within the same automation rule?

If so, have you tryied saving the key before the move using the action Create Variable?  Please see this documentation for more details on that action:

https://support.atlassian.com/jira-software-cloud/docs/automation-actions/

 

Best regards,

Bill

Cédric Cox
Contributor
October 21, 2020

Hi Bill, the create variable is only usable inside the same rule; and at the time the "moved issue" trigger runs, it seems that the prior key is no longer available.

Bill Sheboy
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 21, 2020

Gotcha. 

Well, the changelog history will not help for an option as it does not support the Key field. (There are suggestions/ideas in the Code Barrel (now part of Atlassian) backlog to improve this to add more fields and details in the changelog...The devs are limited by the Jira API as to what is possible...apparently  :^)

One hack/work-around is to create a custom field which, at issue creation, stores the original Key.  That could be accessed in the future for any rule/query/etc.  Bad idea from a data modeling perspective, but it does work-around the Jira limitation.

Cédric Cox
Contributor
October 21, 2020

Well, as a matter of fact, it works... And I don't know why, because it is not documented:

{{changelog.key.fromString}} gives you the previous key, and {{changelog.key.toString}} gives you the new key (as triggerIssue.key).

The key information, as well as the project information are given in the changelog for the issue moved trigger.

So, good job Jira Automation, and thank you Bill for the clue ;-)

Like # people like this
Bill Sheboy
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 21, 2020

Awesome: I am glad that worked for you! 

Looks like they have started implementing some new fields for changelog...when I checked the documentation it still only showed 3 fields available.  Time to explore a bit and see if they added the other requested stuff, such as the specifics of when a change occurred and who made the change.

Cédric Cox
Contributor
October 21, 2020

Thanks Bill, maybe you can help me with another related issue. I try to throw a trigger when a subtask is converted into a story (or a story to a subtasks). Well, there is no such triggers for that, so I tried the "Values change" trigger, pointing the issue type (since this is what is changing in this case...), but it doesn't work.

Maybe I can implement this using an incoming webhook (and try to generate the html post with ... I don't know). 

Any other idea?

Bill Sheboy
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 21, 2020

You may not be able to catch an issue type change with a move (convert) with the automation rules.  Here is a suggestion to add it.

Trigger Issue Move event notification when the Issue type is changed within the same project  https://jira.atlassian.com/browse/JRACLOUD-70640

What problem are you trying to solve by watching for this change?

0 votes
Kevin Dalton
Contributor
October 21, 2020

We do this with a scripted field using scriptunner.

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

Issue issue = issue
IssueManager issueManager = ComponentAccessor.getIssueManager();

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def x = issueManager?.getAllIssueKeys(issue?.id)
x = x.minus(issue?.key)
if (x.join(' ') == "") {
return null
}

return x.join(' ')

Cédric Cox
Contributor
October 21, 2020

Hi Kevin, thanks for your script but I am using Jira Cloud, so a scripted field is not a solution for me. Maybe is there a way to access the history with Jira Automation? 

Apryl Harris August 10, 2022

@Cédric Cox - would the automation you mentioned work to find all the old and new keys after a project was moved from Team-managed to company managed? Will it work if the old project has been permanently deleted?

Can you send the exact automation you used? maybe i can edit to find what I'm looking for?

Use case: trying to get the old/new key match for all issues in a project without having to do new project export and vlookups. 

Thank you.

Cédric Cox
Contributor
August 10, 2022

Hi Apryl,

 

I really don't know if it will work for your use case because the initial trigger is not the same. The "issue moved" trigger contains a changelog that can easily be accessed, and that is what I did as you can see below. You try to access this changelog after the event (not during it as I did). Maybe you should try to parse the issue history log with an automation rule to find the old key. I think that if you can see it on the issue history tab on the issue page, it can be accessed with automation.

If automation does not work, you can still try to access it with a JIRA api call in automation.

You can find below how I accessed the changelog with automation to retrieve the old key event if I think that will not help you.

Regards,

Cédric

 

temp.jpg

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events