Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Copy fixVersion to task in another project

Müller_ Julian October 2, 2020

Hello,

i have a problem with copying the fixversion from task in project A to task in projekt B. The copying works well and I have also some entries in the history-tab, but i can't filter for these version in the projekt releases view.

I think, the problem is that each project has unique versions, even if i name them the same and my script copies the version from project A to my task in project B. The name is the same but the ID is different.

How can I change my script to make this work? I think, that i have to compare the versions i get from project A to the versionlist of project B but I don't know how.

This is an extract of my script:

// Check if fixVersion is updated
if (LastChangeDate != null){
LastChangeDateFormat = LastChangeDate.format("yyyy-MM-dd hh:mm:ss")
}
if (LastChangeDateFormat >= currentDate) {
log.debug("${issueKey} fixVersions changed ${LastChangeDate}")
def fixVersions = issue.getFixVersions()
log.debug("FixVersion lautet ${fixVersions}")


// Updating FixVersions in Customer Issue
if (issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
for (IssueLink link in issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
def destIssueCust = link.getDestinationObject()
//versionManager.updateIssueFixVersions(destIssueCust, fixVersions);
//ComponentAccessor.getIssueManager().updateIssue(CurrentUser, missue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false);
destIssueCust.setFixVersions(fixVersions)
ComponentAccessor.getIssueManager().updateIssue(CurrentUser, destIssueCust, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false);
log.debug("${issueKey} fixVersions changed in customer issue ${destIssueCust}")
}
}

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Müller_ Julian October 4, 2020

I found a solution. I added a loop were the fixversion is cut into the different versions, saves as a string and after that i searched for this string in the projekt versions of the linked issue.

The problem was that we have the same release in different projects and my script copies version from the project A to project B with the false ID.

This is my new code:

// Check if fixVersion is updated
if (LastChangeDate != null){
LastChangeDateFormat = LastChangeDate.format("yyyy-MM-dd hh:mm:ss")
}
if (LastChangeDateFormat >= currentDate) {
log.debug("${issueKey} fixVersions changed ${LastChangeDate}")
def fixVersions = issue.getFixVersions()
log.debug("FixVersion DEV-Ticket lautet ${fixVersions}")

// Updating FixVersions in Customer Issue
if (issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
for (IssueLink link in issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
def destIssueCust = link.getDestinationObject()
def projectCust = destIssueCust.getProjectObject().getId();
def versionsCust = []
log.debug("Projekt = ${projectCust}")
for (version in fixVersions) {
String strVersion = version
versionsProject = versionManager.getVersion(projectCust, strVersion)
versionsCust.add(versionsProject)
}

destIssueCust.setFixVersions(versionsCust)
log.debug("FixVersion CUST-Ticket lautet ${destIssueCust.getFixVersions()}")
ComponentAccessor.getIssueManager().updateIssue(CurrentUser, destIssueCust, com.atlassian.jira.event.type.EventDispatchOption.ISSUE_UPDATED, false);
log.debug("${issueKey} fixVersions changed in customer issue ${destIssueCust}")
}
}
0 votes
Gustavo Félix
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 3, 2020

@Müller_ Julian Hi
Can you try moving your issue to "Done"  ? 
I was trying a similar code and the fix version is copied into my issue, but when I search in jql, there were no results.

I move the issue to Done, and then the jql worked .

Let me know if this works.

Gustavo Félix
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 3, 2020

I forgot to add this.

Here , I search for X version . 
Then I search in the list of versions and add to another list of versions the one that I need.

List<Version> vers = ComponentAccessor.getVersionManager().getVersionsByName("test") as List
List<Version> issueVersions = new ArrayList<Version>()
//This will print the project Name of each version
log.warn vers.get(0).getProject()
log.warn vers.get(1).getProject() 
//Since I know I want the version with id 1
issueVersions.add(vers.get(1))
issueToBeCopied.setFixVersions(issueVersions)

issueManager.updateIssue....

Let me know if you try it.



Müller_ Julian October 4, 2020

I found a solution. I added a loop were the fixversion is cut into the different versions, saves as a string and after that i searched for this string in the projekt versions of the linked issue.

The problem was that we have the same release in different projects and my script copies version from the project A to project B with the false ID.

This is my new code:

// Check if fixVersion is updated
if (LastChangeDate != null){
LastChangeDateFormat = LastChangeDate.format("yyyy-MM-dd hh:mm:ss")
}
if (LastChangeDateFormat >= currentDate) {
log.debug("${issueKey} fixVersions changed ${LastChangeDate}")
def fixVersions = issue.getFixVersions()
log.debug("FixVersion DEV-Ticket lautet ${fixVersions}")

// Updating FixVersions in Customer Issue
if (issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
for (IssueLink link in issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
def destIssueCust = link.getDestinationObject()
def projectCust = destIssueCust.getProjectObject().getId();
def versionsCust = []
log.debug("Projekt = ${projectCust}")
for (version in fixVersions) {
String strVersion = version
versionsProject = versionManager.getVersion(projectCust, strVersion)
versionsCust.add(versionsProject)
}

destIssueCust.setFixVersions(versionsCust)
log.debug("FixVersion CUST-Ticket lautet ${destIssueCust.getFixVersions()}")
ComponentAccessor.getIssueManager().updateIssue(CurrentUser, destIssueCust, com.atlassian.jira.event.type.EventDispatchOption.ISSUE_UPDATED, false);
log.debug("${issueKey} fixVersions changed in customer issue ${destIssueCust}")
}
}

Like Gustavo Félix likes this
0 votes
Müller_ Julian October 2, 2020

Just a little news: I tested to add the fixVersions with Automation for Jira and had no problems.

I also noticed: When using Automation each fix version is deletable, which copying through script i can also delete the whole entry.

TAGS
AUG Leaders

Atlassian Community Events