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

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

0 votes

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

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.


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.

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.

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.

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"}

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"}

no problem ;-)

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}")
}

Hi Adam,

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

Cheers.

F.

Hi,

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

Thanks

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,873 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot