Hello,
I have a requirement to create a sub-task in following situation in groovy script:
Parent
-> When Parent moves to resolved status it generate Sub-task A
->While doing above transition, if Parent has value set to 'No' for a custom field called "Flag", then it will create another sub-task B and it will have link to Sub-task A.
Can someone please help to get the groovy script?
Thank a lot in advance.
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}")
}
}
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.