Jira Groovy Script Runner - Clone an issue and link - avoid creating duplicate clones

I'm trying to use the post-function to clone an issue into a separate project and link it. I've put this post-function on the Resolve transition. Our workflow is such that it is not uncommon (maybe 5% of issues) for issues to be Resolved, but Rejected by our test department, which sends them back into In Progress for a developer to work on it, which will then go back through the Resolve transition.

We have a checkbox to indicate whether the change requires that user documentation be updated - only about 5-10% of all issues need documentation updates.

The way we've set this up so far is to have a separate project for the Documentation team, so they can track and manage their issues separately from the rest of development. They also work to a slightly different time schedule than the rest of us.

Basically what is happening now is that if I move an issue through Resolve, then Reject it, and Resolve it again, the 2nd time through I get another clone of the issue created in the documentation project, but what I want is only 1 unique copy to be created.

I figure the easy way to check for this is that if there is any documentation issue linked to the main issue, upon going through Resolve no new clone needs to be made.

Here's the Groovy condition statement I've got, which clearly isn't working:

cfValues['Documentation Required'].value == 'Yes' && issueLinkManager.getOutwardLinks(issue.getId())*.getDestinationObject().getProjectObject().getName().value != 'Documentation'

I've based this off the "Has at least one outward duplicate link" canned example. I expect that the "getOutwardLinks" is returning a collection and I probably need to loop through that, but I don't really know how to do that when making it into a condition to check.

1 answer

1 accepted

1 vote
Accepted answer

You could write


If you use the *. operator you get a collection of the results of the following 'path' for all elements of the collection. So issueLinkManager.getOutwardLinks(issue.getId())*.destinationObject.projectObject.name contains all names of the projects of the destination issue objects. contains() checks if the element is in the collection and with ! you negate the result of this check.

Exactly... if you use the spread dot operator you need to compare with a list or use "in" or "contains".

This works, thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,310 views 5 11
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you