[Workflow Condition] Verifiy if issue is linked to an issue type

Deleted user March 25, 2013

Greatings Atlassian Community,

In one of my workflow step, I want to create a condition before getting to the following step.

I want the workflow to check if the issue I'm working on, is at least linked to another issue type.

For example : Type A is linked at least to one Type B (no matter

For now (sorry, stil a groovy beginner), I've got this :

issue.componentManager.getIssueLinkManager().getDestinationIssue(issue.issueTypeObject.name)*.value.contains("Type B")

Of course, it doesn't work (otherwise, I won't be here) but I want to know where I'm wrong.

For the record, I'm using JIRA 4.4.1 and the error message in condition tester is :

No such property: componentManager for class: com.atlassian.jira.issue.IssueImpl

Thanks for sharing your experience with me.

Cheers.

Fabien.

2 answers

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.
March 25, 2013

A full condition (for the simple scripted condition) that checks whether has at least one ingoing or outgoing link would be:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getLinkCollectionOverrideSecurity(issue).linkTypes

Deleted user March 26, 2013

Hi Jamie, Adam

After testing your proposal, I couldn't find a way to work it (and I ran out of aspirins).

But, after a long night, I came with this code that I believe to be close from the right one, can you tell me how to fix it?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
 

MutableIssue issue = componentManager.getIssueManager().getIssueObject("BOO-36")
def linkMgr = componentManager.getIssueLinkManager()
def link = linkMgr.getOutwardLinks(issue.id)
MutableIssue issuelinked = componentManager.getIssueManager().getIssueObject(link.getDestinationObject().getId())

issuelinked.getIssueTypeObject()*.name.contains('Release')

Error message is : No signature of method: java.util.ArrayList.getDestinationObject() is applicable for argument types: () values: []

So I guess that it's due to the fact that I get a single value and not a list of value?

Thanks for your help.

Cheers

Fabien.


Deleted user March 27, 2013

Hi everyone,

So I'm still working on this code, and now have this one, but returning no value. For the moment, can't figure out what is missing.

What do you think about it?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.MutableIssue

def issue = componentManager.getIssueManager().getIssueObject("BOO-36")
linkMgr = ComponentManager.getInstance().getIssueLinkManager()

for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {

Issue wanted = link.sourceObject;

wanted.getIssueTypeObject()*.name.contains('Release')

}


Thanks.

Cheers!

F.
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 30, 2013

To look for a specific link "blocks" your condition would be this:

import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).any{it.issueLinkType.name == "Blockers"}

That looks for this issue blocking another. To look for "is blocked by" you would use getInwardLinks. You should be able to adjust this to your needs.

Deleted user April 2, 2013

Hi Jamie,

First, I apologize for my late answer.

if I understand correctly what you wrote, is it something like this but get an error message (No such property: issueLink for class: com.atlassian.jira.issue.link.IssueLink) :

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

def issue = componentManager.getIssueManager().getIssueObject("BOO-36")

def issueLinkManager = componentManager.getInstance().getIssueLinkManager()

issueLinkManager.getOutwardLinks(issue.id).any{it.issueLink.issueTypeObject.name == "Release"}

What can I add in order to declare correctly issueLink? (When checking the 4.4.1 API, it seems correct with issue.link.IssueLink).

Thanks.

Fabien.

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

If you're doing what I think you're doing, which is checking if there are any links to an issue of type Release, your last line should be:

issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.issueTypeObject.name == "Release"}

Deleted user April 2, 2013

Jamie,

What can I say? ...except that you're the best! ;)

Thanks a lot!

Here is the entiere code in case it should help others :

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

def issue = componentManager.getIssueManager().getIssueObject("BOO-36")

def issueLinkManager = componentManager.getInstance().getIssueLinkManager()

issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.issueTypeObject.name == "Release"}

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

no problem ;-)

1 vote
Adam Marszałek
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 25, 2013

Hey,

Here you can find snippet to let you begin. I used it to synchronize linked issues:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import org.apache.log4j.Category

log = Category.getInstance("class")

def componentManager = ComponentManager.getInstance()
def issueLinkManager = componentManager.getIssueLinkManager()

log.debug("Inward links:")
issueLinkManager.getInwardLinks(issue.getId()).each(){l->
    log.debug("Link of type ${l.issueLinkType.name} from ${l.sourceObject} to ${l.destinationObject}")
}

log.debug("Outward links:")
issueLinkManager.getOutwardLinks(issue.getId()).each(){l->
    log.debug("Link of type ${l.issueLinkType.name} from ${l.sourceObject} to ${l.destinationObject}")
}

Deleted user March 25, 2013

Hi Adam,

Thanks for your answer & proposal. I'll try it and let you know!

Cheers.

F.

Teja December 7, 2017

Hi,

Can anyone tell me how validate custom field value for linked issues ?

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events