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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Copy fixVersion to task in another project Edited

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

0 votes
Answer accepted

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}")
}
}

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.

@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.

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.



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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Learn how to request and manage app requests in the Marketplace

G’day everyone! Super exciting news coming from the Marketplace. We have now fully rolled out the ability for end-users to submit app requests to admins directly from within the product! No longer ...

43 views 1 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you