Groovy script validator - Has at least one outward duplicate link

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

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.

Got it,

Thanx Jamie

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

Henning Tietgens Community Champion Apr 02, 2013

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

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

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

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
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,771 views 18 21
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