Groovy script validator - Has at least one outward duplicate link

Tsol
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.
April 1, 2013

Hi everybody,

i'm using groovyrunner validator Has at least one outward duplicate link in a workflow transition. In the workflow screen i have added the linked issues field so i can create a link during transition.

The problem i have is that, if before transition i do not have a duplicate link transtion is never executed.

Is there a problem in linked issue field type?

In validation of custom fields for example i can enter values in transition screen and values are validated.

Thanx in advance,

Kostas

1 answer

1 accepted

1 vote
Answer accepted
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.
April 1, 2013

The sample code for validators (as opposed to conditions) doesn't work, because unlike other issue metadata the issueLinkManager doesn't report any links until the issue is committed to the database.

IMHO this is a jira bug, and the current links should be available by calling a method on the issue.

If you look at previous questions about this @Henning has found a way to do this using the servlet request, although this won't work for programmatic transitions, or remote API calls.

Tsol
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.
April 1, 2013

Got it,

Thanx Jamie

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.
April 1, 2013

AAC got the wrong Henning, it's this one: @henning-tietgens

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.
April 2, 2013

Seems not to work :-) The second link is the same, it's not me :-)

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.
April 2, 2013

I know, I gave up after the second link ;-) It's some inferior low-karma Henning!

Robert Poldervaart April 2, 2013

Based on some help from Henning, I use the following validator script to check for one, and only one, duplicate link during our "Close as Duplicate" step/transition. We use JIRA 4.4.

def issueLinkManager = ComponentManager.getInstance().getIssueLinkManager()
// for version 5.0+
// import ComponentAccessor
//def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def request = ActionContext.getRequest()
if (request) {
    // check for new duplicates link 
    linktype = request.getParameter('issuelinks-linktype')
    linkedIssue = request.getParameter('issuelinks-issues')
    reqLink = (linktype == 'duplicates' && linkedIssue)
}

// check for existing duplicates link
oldLink = issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate')

// Transition requires one, and only one, duplicates link
// XOR reqLink and oldLink
if ( ! reqLink ^ oldLink ) invalidInputException = new InvalidInputException("Close as Duplicate requires One, and only One, link with type = 'duplicates'.

Jeannette Lamb March 19, 2014

I am having a similar issue. I want to add a validator to the Create transition to check if Linked Issues has at least one issue with the "tests" link type. I.e. I'm trying to make sure a Test issue type can't be created unless it has been linked to at least one User Story. I tried the code above with "tests" but it doesn't work.

Well, it works, but it always fails validation, even when I have added a link type "tests" and selected an issue.

We are using JIRA 6.0.8.

Thanks in advance!

Jeannette

Suggest an answer

Log in or Sign up to answer