Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script Runner Conditions - Issue Links

Baybars Kumbasar April 21, 2016

Hello,

I'm using the ScriptRunner plugin from adaptavist, specifically  script function "Clones an issue and links".

I have no experience in Java & Groovy (I'm not a programmer) at all but I would like to write a simple "Condition" that will only process the function if there are no existing links to the issue. Link type does not matter much but it would be preferable if I could check to see if the link type is "is blocked by" .

I tried to use the example code and modify it a bit:

 

issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains!('is blocked By')

 

But when I use this condition, no action is performed even though the ticket has not any links with the type "is blocked by". What am I doing wrong? 

 

Thanks,

Baybars

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

7 votes
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 21, 2016

The name will be something Blockers. The inward or outward description might be "is blocked by". You should check at Admin -> Issue Linking or whatever it is.

So a condition would be:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager

def issueLinkManager = ComponentAccessor.getComponent(IssueLinkManager)

! issueLinkManager.getOutwardLinks(issue.getId()).any {
    it.issueLinkType.name == "Blockers"
}

 

 

Baybars Kumbasar April 21, 2016

I've changed the name of "Blockers" to "is blocked by" (this is what I understood from your post), the syntax is correct but it still performs the script even if the issue has been linked to another issue. 

Is there a method to see if the condition we've set actually is met or not for the issue? 

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 21, 2016

From Issue Linking you shd see something like: image2016-4-21 19:50:54.png

The highlighted thing is the name, it's almost certainly not "is blocked by".

If that doesn't work maybe you want getInwardLinks, depending on what you're trying to do.

IIRC the simple scripted condition lets you trial the condition with a sample issue.

Baybars Kumbasar April 22, 2016

Thanks Jamie , it worked with "getInwardLinks" .

 Can you elaborate on: "IIRC the simple scripted condition lets you trial the condition with a sample issue." This would be very useful for the future. 

Mark McCormack (Adaptavist)
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 29, 2016

Hi Baybers,

I think Jamie is referring to the Preview button available in the Scripted Post Function when you choose "Clone & Link".

I just tried it and the Preview button does not accept a sample issue as a parameter (on this occasion).

There are many scenarios where the Preview button does let you input an issuekey so you can try it out. 

Serj Shcherbakov May 12, 2017

@Jamie Echlin, thanks a lot!

0 votes
J.Fawkes April 21, 2016

Hi,

Have you tried this:
if(!issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('is blocked By') )

That means that issue LinkType isn't "is blocked By"

Baybars Kumbasar April 21, 2016

this did not work, it did not like the if statement. I think because this already is a "condition", you don't need a if statement. 

TAGS
AUG Leaders

Atlassian Community Events