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

Greg Hoggarth March 10, 2014

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
Answer accepted
Henning Tietgens
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.
March 10, 2014

You could write

!issueLinkManager.getOutwardLinks(issue.getId())*.destinationObject.projectObject.name.contains('Documentation')

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.

JamieA
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.
March 10, 2014

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

Greg Hoggarth March 11, 2014

This works, thanks!

Suggest an answer

Log in or Sign up to answer